// Throw an exception
Exception up = new Exception("Something is really wrong.");
throw up; // ha ha
// Catch an exception
try
{
y = 0;
x = 10 / y;
}
catch (Exception ex) // Argument is optional, no "When" keyword
{
Console.WriteLine(ex.Message);
}
finally
{
Microsoft.VisualBasic.Interaction.Beep();
}
|
*> Throw an exception
declare exc = new Exception("Something is really wrong.");
raise exc
*> Catch an exception
declare x y as binary-long
try
declare o as string = null
display o[0] *> display first character
catch ex as type Exception
display ex
finally
display "Finally"
end-try
|
' Throw an exception
Dim ex As New Exception("Something is really wrong.")
Throw ex
' Catch an exception
Try
y = 0
x = 10 / y
Catch ex As Exception When y = 0 ' Argument and When is optional
Console.WriteLine(ex.Message)
Finally
Beep()
End Try
' Deprecated unstructured error handling
On Error GoTo MyErrorHandler
...
MyErrorHandler: Console.WriteLine(Err.Description)
|