A simple library for adding universal exceptions more additional meta than the common std::exception while preserving the original code when integrating.
- StackTrace - Support to get the stack tree of when it was invoked.
- Unicode - Allow support for both ASCII, Unicode 8, and unicode 16.
- Backward compadible with standard exception.
Attempt to create a dedicated Exception library with useful debug info and stack trace info while maintaining the standard c++ exception. Allowing to reuse the code in multiple projects with a good level of information when the exception is thrown.
The library can be built simply by the following commands.
mkdir build
cd build
cmake ..
make
A note, this exception library is using external submodule git. Use the following command to download all the dependent git repositories.
git submodule update --init --recursive
The idea is to be able to integrate this library with another project easily. With CMake, it basically requires 2 lines. One for adding the project and the second for adding it as a dependent linked library target.
ADD_SUBDIRECTORY(exceptCXX EXCLUDE_FROM_ALL)
TARGET_LINK_LIBRARIES(myTarget PUBLIC cxxexcept)
The dependices currently is related to backward-cpp
apt install binutils-dev
The following is a simple example for throwing an exception, followed by printing a formated error message to stdout.
try {
throw cxxexcept::DivideByZeroException();
} catch (const std::exception &ex) {
cxxexcept::printStackMessage(ex);
}
Another example, using a more common exception type, runtime exception.
try {
throw cxxexcept::RuntimeException();
} catch (const std::exception &ex) {
cxxexcept::printStackMessage(ex);
}
Getting a comprehensive string of both the stack as well the cause of exception can be extracted with the following method.
std::cerr << cxxexcept::getStackMessage(ex);
This project is licensed under the MIT License - see the LICENSE file for details