Feature #8841

Add ability to hook into WException creation/destruction

Added by Roel Standaert 6 months ago. Updated about 1 month ago.

Target version:
Start date:
Due date:
% Done:


Estimated time:


There are many implementations for generating stack traces. Currently Wt supports libunwind, adding the stack trace to what(), but there are many others.

When using services like Sentry it would be nice to use Sentry's own stack trace functionality, so it can be attached to the event sent to Sentry when the exception is caught.

To do this, we could add the ability for developers using Wt to globally register a hook that gets triggered upon creation (and maybe also deletion) of a WException.

How the user would then attach their own stack trace information is still an open question. We could:

  • Allow attaching arbitrary data to the WException using std::any (with the caveat that copying an object into std::any should be noexcept, since we should not have the constructor or destructor of an exception throw). We could also use void *, but this may be more difficult to use correctly.
  • Just let the developer keep their own (thread safe) data structure that maps WException pointers to extra associated data.
  • Let the developer change the message.

There's also the caveat that if WException is derived from, that type information is not available in the constructor or destructor of WException. We currently have a few exception types that derive from WException. We could just leave this as a caveat?

We can do something similar with Wt::Dbo::Exception.


Updated by Roel Standaert 6 months ago

  • Description updated (diff)

Updated by Roel Standaert about 1 month ago

  • Target version deleted (future)

We found a better way to do this, by hooking into __cxa_throw, so we may not put this in Wt after all.

Also available in: Atom PDF