I know I cannot throw exceptions from a DLL, it will crash. So I currently use a wrapper that collects exceptions and pick it up if the wrapper method returns a failure state.

As I know what type of exception will be thrown, I can copy all important data to a new exception object and then throwing it in the current context.

However, I wonder if there is way to copy the exception data via Throwable interface direct because checking for types via typeid() and string comparsion is just meh.

It is possible to fetch the exception data:

// Throwable e;

// this returns null in the program (but works in a debugger watch):
MyExceptionObj imported = cast(MyExceptionObj)e;

// this actually works:
MyExceptionObj imported = cast(MyExceptionObj) cast(void*)e;

But for some reason throwing this object directly would crash.

Is there are way to copy the exception data in a new Throwable instance that can be thrown from the current context? Or can the runtime be tricked by overwriting the TypeInfo in memory? (I don't know exactly what the actual problem is.)

Reply via email to