external: update backward-cpp to v1.4
rename the directory name to backward-cpp Closes: #803 Signed-off-by: Shengjing Zhu <i@zhsj.me>
This commit is contained in:
parent
8bed54cb24
commit
5e35efbf73
26 changed files with 4001 additions and 2083 deletions
60
external/backward-cpp/test_package/main.cpp
vendored
Normal file
60
external/backward-cpp/test_package/main.cpp
vendored
Normal file
|
|
@ -0,0 +1,60 @@
|
|||
#include <backward/backward.hpp>
|
||||
#include <iostream>
|
||||
#include <stdexcept>
|
||||
#include <sstream>
|
||||
|
||||
using namespace backward;
|
||||
|
||||
class TracedException : public std::runtime_error
|
||||
{
|
||||
public:
|
||||
TracedException() :
|
||||
std::runtime_error(_get_trace())
|
||||
{}
|
||||
|
||||
private:
|
||||
std::string _get_trace()
|
||||
{
|
||||
std::ostringstream ss;
|
||||
|
||||
StackTrace stackTrace;
|
||||
TraceResolver resolver;
|
||||
stackTrace.load_here();
|
||||
resolver.load_stacktrace(stackTrace);
|
||||
|
||||
for(std::size_t i = 0; i < stackTrace.size(); ++i)
|
||||
{
|
||||
const ResolvedTrace trace = resolver.resolve(stackTrace[i]);
|
||||
|
||||
ss << "#" << i << " at " << trace.object_function << "\n";
|
||||
}
|
||||
|
||||
return ss.str();
|
||||
}
|
||||
};
|
||||
|
||||
void f(int i)
|
||||
{
|
||||
if(i >= 42)
|
||||
{
|
||||
throw TracedException();
|
||||
}
|
||||
else
|
||||
{
|
||||
std::cout << "i=" << i << "\n";
|
||||
f(i + 1);
|
||||
}
|
||||
}
|
||||
|
||||
int main()
|
||||
{
|
||||
try
|
||||
{
|
||||
f(0);
|
||||
} catch (const TracedException& ex)
|
||||
{
|
||||
std::cout << ex.what();
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Loading…
Add table
Add a link
Reference in a new issue