Giter VIP home page Giter VIP logo

exceptcxx's Introduction

ExecptCXX

ExceptCxx License: MIT GitHub release

A simple library for adding universal exceptions more additional meta than the common std::exception while preserving the original code when integrating.

Features

  • 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.

Motivation

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.

Installation

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 

Integration with CMake

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)

Dependencies

The dependices currently is related to backward-cpp

apt install binutils-dev

Examples

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);

License

This project is licensed under the MIT License - see the LICENSE file for details

exceptcxx's People

Stargazers

 avatar  avatar

Watchers

 avatar  avatar  avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.