IntControl(73, p1, p2, p3, 0)
Sets Error handler.
This IntControl lets you specify what should happen when the next error occurs in the script.
p1 Meaning
-1 Don't change (just return current setting)
0 Normal error processing (default)
1 Goto the label :WBERRORHANDLER
2 Gosub the label :WBERRORHANDLER
3 Call the UDF specified by p3
p2
@TRUE or @ FALSE. Specifies whether any existing "wberroradditionalinfo" data should be cleared first. This is a one-time flag, which gets reset to 0 after the next error occurs.
p3
Name of the error handling UDF.
The error handler UDF must be defined to accept exactly one parameter. The parameter it receives will be the "wberrorarray" array. None of the other WIL variables will be automatically set.
The return value of the error handling UDF has special meaning. The following values may be specified:
Value |
Meaning |
0 |
(default) UDF error handling is canceled. |
1 |
Continue handling error events with this UDF. |
2 |
Treat this error event as unhandled, and do normal error processing |
3 |
Treat this error event as unhandled, but continue handling errors with this UDF. |
If the error handler UDF is invoked during a variable assignment statement (eg, "variable = function()"), and you set wberrorarray[11] to a specific value inside the handler UDF, that value will be assigned to the variable (x). Note that this does not work for a property assignment. By default, the value assigned when an error occurs is 0.
When processing goes to :WBERRORHANDLER, the following WIL variables are automatically set:
Variable |
Type |
Meaning |
wberrorhandlerline |
(s) |
Error line (i.e., line in script that caused Error) |
wberrorhandleroffset |
(i) |
offset into script of error line, in bytes |
wberrorhandlerassignment |
(s) |
variable being assigned on error line, or "" if none |
wberrorhandlerfile |
(s) |
name of the currently-executing script |
wberrortextstring |
(s) |
description of the WIL error |
wberroradditionalinfo |
(s) |
delimited string of additional error information, if any. ASCII 160 is delimiter character between each error incident. |
wberrorinsegment |
(s) |
name of the currently-executing UDF, or a blank string ("") if not in a UDF. |
wberrorhandlerlinenumber |
(i) |
line number in the currently executing script or 0 if the error cannot be matched to a particular line. |
wberrorarray |
(a) |
WIL array with the following elements: wberrorarray[0] = LastError()
|
Returns
Returns previous setting.
Notes:
The :WBERRORHANDLER label or User Defined Function/User Defined Subroutine must be in the same script where the error occurred. If an error occurs in a called script, it will go to the label in the called script, not the calling script.
If you want to have error handling occur within a User Defined Function / User Defined Subroutine, then IntControl 73 must be called from within the User Defined Function/User Defined Subroutine.
If you want the script to continue to handle errors, make sure to re-arm the error handler by calling IntControl 73 at the end of your error handling routine.
Getting Extended Error Information:
Most WIL errors are accompanied by 'extended error information'. Extended error information is written to the wwwbatch.ini file:
On XP: "C:\Documents and Settings\{username}\Application Data\WinBatch\Settings\wwwbatch.ini"
On Vista and newer: "C:\Users\{username}\AppData\Roaming\WinBatch\Settings\wwwbatch.ini"
There is a section that contains additional diagnostic information that may give some clue as to what it is that failed.
IntControl 73 returns this same information in the 'wberroradditionalinfo' variable.
Extended error information is most commonly in the form of a Windows system error. For a list of Windows system errors see Microsoft's website: Windows System Error Codes
Example:
;GOTO Sample
IntControl(73,1,0,0,0) badline=Message(aaaa,bbb) Exit
:WBERRORHANDLER lasterr = wberrorarray[0] handlerline = wberrorarray[1] textstring = wberrorarray[5] linenumber = wberrorarray[8] errstr = StrCat("Number: ",lasterr,@LF,"String: ",textstring,@LF,"Line (",linenumber,"): '",handlerline,"'") Message("Error Information",errstr) Exit
;GOSUB sample IntControl(73,2,0,0,0) badline=Message(aaaa,bbb) Exit
:WBERRORHANDLER lasterr = wberrorarray[0] handlerline = wberrorarray[1] textstring = wberrorarray[5] linenumber = wberrorarray[8] errstr = StrCat("Number: ",lasterr,@LF,"String: ",textstring,@LF,"Line (",linenumber,"): '",handlerline,"'") Message("Error Information",errstr) IntControl(73,2,0,0,0) ; Re-Arm error handler Return
;UDF sample #DefineSubRoutine OnNextError(Err_Array) lasterr = wberrorarray[0] handlerline = wberrorarray[1] textstring = wberrorarray[5] linenumber = wberrorarray[8] errstr = StrCat("Number: ",lasterr,@LF,"String: ",textstring,@LF,"Line (",linenumber,"): '",handlerline,"'") Message("Error Information",errstr) Return(1);Re-arm error handler #EndSubRoutine
IntControl(73,3,0,"OnNextError",0) badline=Message(aaaa,bbb) Exit