Error Handling

Top  Previous  Next

The obsolete error handling routines as OnError, LastErrorLine, LastErrorPos has been removed from latest versions of the LMD-ScriptPack. The error handling from now is based on Delphi exceptions mechanism only.

From now, all additional information about the exception, e.g. script control reference, error-line and error-pos is encoded directly into the error message string. Of course, this is not a perfect way, but there are several reasons to do so:


First, running script and used in it object model, can raise exceptions of any particular class. Thus, it is impossible to declare some exception class that can provide error-line and error-pos in natural way.
Second, it is impossible to preserve the class of exception while it cross IDispatch invocation bounds in Active Scripting languages.


Thus, script control encodes the information directly into the error message, and the message looks like this:



You can catch the exceptions raised from the script, and decode the information. Use LMDDecodeErrorMessageInfo function to determine the original message, script control, and error line and pos. You can also use LMDHasErrorMessageInfo function to check, whether the error information is encoded into the message.


Note, that the native scripting languages, such as PasScript and NativeVB, use true exception handling, and exception instance raised somewhere will reach your parent application (of course, if not caught and handled by script code). Only message will be changed; the instance of the exception object will be the same.

Unlike native scripting languages, it is impossible to preserve exception in Active Scripting languages, because IDispatch interface is not compatible with Delphi exception system. Thus, an exception, raised in your object model inside a script will be converted at the IDispatch invocation boundary, and the application will get another exception instance, probably, of another class. Only the message will correspond to initial exception.


For organize true debugging capabilities, instead of simple errors catching, use TLMDScriptDebugger component.