Workaround to "import" an exception from a DLL
frame
frame86 at live.com
Sun Mar 14 09:35:40 UTC 2021
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.)
More information about the Digitalmars-d-learn
mailing list