Unexpected errors that occur at runtime can be handled via the script language's own error handling facilities.
The two scripting languages available in Newlook have different ways of handing runtime errors:
JScript uses the try
, catch
, finally
, and throw
statements for error
handling. The syntax is as follows:
try { //try Statements } catch(error) { var description = "Message: " + error.description + "\n" "Error Code: " error.number + "\n";
App.MsgBox(description, "Error"); } finally { //finally Statements } |
The try
statement is where errors may occur. If an error
occurs inside the try block, then it will be thrown. You can nest try blocks.
The catch
statement
is optional, but it lets you handle the error. The exception
is a required parameter of catch. Set it to any variable. Initially this
variable will be set to the value of the thrown error when entering the
catch statement.
The finally
statement is also optional. If present, then
the finally statements will be executed after try and catch, regardless of the result.
The throw
statement lets you create custom errors.
JScript has its own error object. When a runtime error occurs, the properties of this error object are filled with information that identifies the error, and that you can use to handle the error. Available properties:
The JScript Error object is different to the Newlook App.Err object. The latter object is only populated when an error occurs in macro execution.
VBScript uses the On Error
statement for error handling. The On Error
statement works on a per-procedure level. Inside each procedure, you must
place the On Error statement. When an error occurs in that procedure,
program control will go to the code immediately following the On Error
statement. The On Error statement can be used in one of two ways:
This is known as in-line error handling. The code following the On Error statement is executed if an error occurs with the procedure that has the On Error statement.
This disables error handling if it has been previously enabled with On Error Resume Next.
Inside the Error handler, you can use the VB Script Err object, to find out more about the error and to raise another error or to reset the Err object. The Err object has the following properties that you can query:
The VB Script Err object is different to the Newlook App.Err object. The latter is only populated when an error occurs in macro execution.
© 2004-2021 looksoftware. All rights reserved.