Exceptions: Difference between revisions

Content deleted Content added
PureFox (talk | contribs)
Added FreeBASIC
Line 1,079:
Note that CATCH only restores the stack pointers, not the stack values, so any values that were changed during the execution of the token will have undefined values. In practice, this means writing code to clean up the stack, like this:
<lang forth>10 ['] myfun catch if drop then</lang>
 
=={{header|FreeBASIC}}==
FreeBASIC does not support exceptions or the Try/Catch/Finally statement, as such.
However, you can use the Err() function, together with a Switch statement, to provide somewhat similar functionality:
<lang freebasic>' FB 1.05.0 Win64
 
Enum ErrorType
myError = 1000
End Enum
Sub foo()
Err = 1000 ' raise a user-defined error
End Sub
Sub callFoo()
foo()
Dim As Long errNo = Err ' cache Err in case it's reset by a different function
Select Case errNo
Case 0
' No error (system defined)
Case 1 To 17
' System defined runtime errors
Case myError: ' catch myError
Print "Caught myError : Error number"; errNo
Case Else
' catch any other type of errors here
End Select
' add any clean-up code here
End Sub
 
callfoo()</lang>
 
{{out}}
<pre>
Caught myError : Error number 1000
</pre>
 
=={{header|Go}}==