Calling a Delphi side function from a script that raises an exception raises a generic EDelphi exception on the script side. This hides the exception class of the actual Delphi side exception. I tried to investigate the implementation of the EDelphi Ijaddajadda interface but am lacking skills to see a way to extract the Delphi side class or at least the class name. The truth has to be out there...
Example, script side
Try
MyDelphiSideFunction; // May raise EOutOfmemory
Except on E:Exception do
PrintLn(E.ClassName);
End;
This always prints "EDelphi", no matter the actual Delphi side exception class (EOutOfmemory in this example).
How to get the "real" class or class name from E?
You cannot directly get the exception class type as the DWScript exception handler doesn't store that information anywhere and the Delphi side type wouldn't make sense inside the script anyway. You can however easily get the class name from the
EDelphiscript side exception object via theEDelphi.ExceptionClassproperty. Like this:Script
Output
You can see the DWScript source code that transforms a Delphi side exception to a script side
EDelphiexception here: https://github.com/EricGrange/DWScript/blob/2d61c8a95fb4a2aab328f3cc84bb9f243c927286/Source/dwsExprs.pas#L2244How I found the answer
I simply searched the source on Github (the search on the main Bitbucket repo sucks) for "EDelphi": https://github.com/search?q=repo%3AEricGrange%2FDWScript%20EDelphi&type=code
This gave me this piece of code:
I then looked at the
CreateEDelphiObjmethod:This looks like a call to a script side constructor, passing the
ClassNameandMessagestrings as parameters. That's fine, but what happens to theClassNamevalue?Again, looking at the search result I noticed the Delphi side implementation of the
EDelphiconstructor:So the constructor calls the inherited constructor and then stores the
ClassNamevalue in theFExceptionClass(the value of theSYS_EDELPHI_EXCEPTIONCLASS_FIELDconstant) field.At this point I could guess that the property would be called
ExceptionClassso I used my DWScriptStudio IDE/debugger to write the example and verify the result.