GithubHelp home page GithubHelp logo

jeremyagost / dispatch_noexcept Goto Github PK

View Code? Open in Web Editor NEW
3.0 3.0 0.0 23 KB

A library intended to make it easier to debug uncaught exceptions when using libdispatch

License: MIT License

CMake 2.39% C++ 49.50% C 48.11%

dispatch_noexcept's Introduction

dispatch_noexcept

This is a library intended to make it easier to debug uncaught exceptions in code that makes use of libdispatch. Any blocks excuted with dispatch_client_callout are enclosed in an Objective-C try/catch block that invokes objc_terminate() if an exception isn't caught. While the end result is roughly the same as a typical unhandled exception program termination, it can make it somewhat harder to debug the uncaught exception. This library wraps the block in a new try/catch that will record and print the stack trace of the dispatch invocation.

How To Use

The Xcode project is configured to build a shared library target. Include the "dispatch.h" header and use dispatch functions as normal. Every instance of an overriden dispatch function will add a compiler warning message indicating that the function is being overriden. The original functions are also redeclared as *_noexcept (e.g. dispatch_async_noexcept) if you want to use them in a context where you know exceptions won't be thrown.

Stack Logging

Call gc_dispatch_except_log_backtrace(true) to enable logging of backtraces when an uncaught exception blows up. Of course there's some overhead. When traces are enabled, you'll get something like this printed to stderr:

FATAL APPLICATION ERROR -- An uncaught exception was intercepted before it could hit libdispatch and trigger an undefined behavior fault. Exception will be rethrown in C++ context. Block callee backtrace:
0   libdispatch_noexcept.dylib          0x00000001000acb1d _Z26_gc_dispatch_get_backtracev + 125
1   libdispatch_noexcept.dylib          0x00000001000af643 _ZL21_dispatchRethrowBlockIJEEDtfp_EU13block_pointerFvDpT_E + 403
2   libdispatch_noexcept.dylib          0x00000001000afd8d _gc_dispatch_after_with_exception_handler + 29
3   test_with_dispatch_noexcept         0x0000000100000e43 _Z16dispatch_throwerv + 67
4   test_with_dispatch_noexcept         0x0000000100000e97 main + 39
5   libdyld.dylib                       0x00007fff9c71f235 start + 1
libc++abi.dylib: terminating with uncaught exception of type std::runtime_error: A nasty error has occurred

Testing

There are two binary targets, test_with_dispatch_noexcept and test_without_dispatch_noexcept, that can be used to demonstrate the different exception handling behavior.

Platform Support

An Xcode project is provided for building the shared library on macOS. A CMakeList file is provided for building on Win32 or Linux, if that's helpful for you.

Authors

License

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

dispatch_noexcept's People

Contributors

jeremyagost avatar

Stargazers

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