Firebreath promise reject slicing exception

109 Views Asked by At

Is there a way to pass any meaningful message, not “std::exception” to the promise’s fail callback? In the sources I found the following “void FB::variantDeferred::reject(std::exception e) const” specification. It seems when reject is called with any exception derived from std::exception the slicing happens and the right exception’s message is lost. Is there any workaround but to pass error through success callback?

1

There are 1 best solutions below

3
taxilian On

std::exception is simply a base class for creating exceptions in C++. You can use a number of different methods to pass a specific string back; for example, you could throw a std::runtime_error, which accepts a message.

You could also subclass std::exception and provide an implementation of std::exception::what which returns a useful string representation of what you want.

FireBreath 2.0 will use the error message from e.what() when it creates the Error object. You can find this in the code, if you're curious how that works: