Only catch errors causing the script to exit
Posted: 22 Jul 2016, 15:50
I would like to use try over a large block of code (a whole script, really), but I don't want it to catch ErrorLevel-type runtime errors. I want to only catch those that would cause the script to stop executing. Alternatively, if it does catch an ErrorLevel-type error, I would like to have it continue executing on the line following the one that caused the ErrorLevel. I can determine in the catch block whether the error was an ErrorLevel type or not, but I can't get it to continue where it left off once I've determined that. Is that possible?
In the following demonstration/test code, I'd like it to display only the MsgBox saying "Show me."
In the following demonstration/test code, I'd like it to display only the MsgBox saying "Show me."
Code: Select all
try
{
ImageSearch, x, y, 0, 0,100,100, image.png
MsgBox, Show me.
obj := ComObjCreate("ScriptControl")
obj.ExecuteStatement("MsgBox ""This is embedded VBScript""")
obj.InvalidMethod() ; This line produces a runtime error.
MsgBox, Don't show me.
}
catch e
{
ErrorMessage := e.message
if ErrorMessage is not integer
{
MsgBox, % "A non ErrorLevel error has occurred.`n`n" e.message "`n`nExiting script."
ExitApp
}
MsgBox, % "ErrorLevel: " e.message
}