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:
Shengjing Zhu 2018-07-08 00:21:50 +08:00
commit 5e35efbf73
26 changed files with 4001 additions and 2083 deletions

View file

@ -0,0 +1,8 @@
project(backward-package-test)
cmake_minimum_required(VERSION 2.8)
include(${CMAKE_BINARY_DIR}/conanbuildinfo.cmake)
conan_basic_setup(TARGETS)
add_executable(example main.cpp)
target_link_libraries(example PRIVATE ${CONAN_TARGETS})

View file

@ -0,0 +1,14 @@
from conans import ConanFile, CMake
import os
class TestBackward(ConanFile):
settings = 'os', 'compiler', 'build_type', 'arch'
generators = 'cmake'
def build(self):
cmake = CMake(self)
cmake.configure(defs={'CMAKE_VERBOSE_MAKEFILE': 'ON'})
cmake.build()
def test(self):
self.run(os.path.join('.', 'bin', 'example'))

View 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();
}
}