Created
June 1, 2021 16:03
-
-
Save JoeGlines/b14e4d8a72b471accd6ac47b1aea2a15 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#SingleInstance,Force | |
;**********Example 1**************************** | |
If (0){ | |
try { ; Attempts to execute code. | |
HelloWorld() | |
MakeToast() | |
}catch e { ; Handles the first error/exception raised by the block above. | |
MsgBox, An exception was thrown!`nSpecifically: %e% | |
} | |
} | |
HelloWorld() { ; Always succeeds. | |
MsgBox, Hello, world! | |
} | |
MakeToast() { ; Always fails. | |
throw A_ThisFunc " is not implemented, sorry" ; Jump immediately to the try block's error handler: | |
} | |
;**********Example_2********************************************* | |
If (0){ | |
try{ | |
obj := ComObjCreate("ScriptControl") | |
obj.ExecuteStatement("MsgBox ""This is embedded VBScript""") | |
;~ obj.InvalidMethod() ; This line produces a runtime error. | |
} catch e { | |
MsgBox, 16,, % "Exception thrown!`n`nwhat: " e.what ;Note the e is an object | |
. "`nfile: " e.file | |
. "`nline: " e.line | |
. "`nmessage: " e.message | |
. "`nextra: " e.extra ; For more detail about the object that e contains, see Exception(). | |
} | |
} | |
;********************Example_3*********************************** | |
If (0){ | |
try SomeFunction() | |
catch e | |
MsgBox % "Error in " e.What ", which was called at line " e.Line " and message " e.message | |
SomeFunction() { | |
throw Exception("this really sucked", -1) | |
} | |
} | |
;********************Example_4* Disregarding Errors********************************** | |
If (0){ | |
ComObjError(1) ;This is optional but not recommended | |
pwb:=WBGet() | |
doo:=pwb.getElementsByTagName("doo").item[0].outerhtml | |
dah:=pwb.getElementsByTagName("dah").item[0].outerhtml | |
dah:=pwb.getElementsByTagName("fda").item[0].outerhtml | |
dah:=pwb.getElementsByTagName("dfh").item[0].outerhtml | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment