Exceptions/Catch an exception thrown in a nested call: Difference between revisions

m
→‎{{header|AutoHotkey}}: Minor indentation and casing edit
(+ AutoHotkey)
m (→‎{{header|AutoHotkey}}: Minor indentation and casing edit)
Line 134:
Here is one way to keep track of nested errors:
<lang AutoHotkey>foo()
Return
return
 
foo()
{
bar(0)
if instr If InStr(ErrorLevel, "U0")
Msgbox MsgBox caught error: U0
bar(1)
if instr If InStr(ErrorLevel, "U0")
Msgbox MsgBox caught error: U0
}
 
bar(i)
{
StringReplace, ErrorLevel, ErrorLevel, baz_error, , All ; clear baz_error(s)
if If !baz(i)
ErrorLevel .= "baz_error" ; add baz_error to errorstack
}
 
baz(i)
{
StringReplace, ErrorLevel, ErrorLevel, U1, , All ; clear U1 errors
StringReplace, ErrorLevel, ErrorLevel, U0, , All ; clear U0 errors
ifIf i
ErrorLevel .= "U1" ; add U1 errors to errorstack
Else
ErrorLevel .= "U0"
Return 1
return 1
}</lang>