Try / Catch / EndTry
Try / Catch / EndTry (Statement)
Format
try
(tab)statement(s)
catch
(tab)statement(s)
end try
Description
Execute the statement(s) inside the try. If a runtime error or a warning happens, the rest of the try part is skipped and the program jumps to the code in the catch. If nothing goes wrong, the catch part is skipped. Either way the program carries on after end try, which may also be written endtry.
- Errors that happen inside a Subroutine or Function called from the try are caught too.
- A try may be put inside another try. An error in the catch part of the inner one goes to the outer catch.
- A try comes before an OnError trap: an error inside a try goes to its catch.
In the catch, LastError, LastErrorLine and LastErrorMessage tell you which error it was.
Example
for t = -1 to 1
try
print "9/"+t + "= " + (9/t)
catch
print "division by zero"
end try
next t
will display
9/-1= -9.0
division by zero
9/1= 9.0
See Also
Error Codes, Lasterror, Lasterrorextra, Lasterrorline, Lasterrormessage, Offerror, Onerror, ThrowError, Try / Catch / EndTry
History
| 1.0.0.2 | New To Version |