Exception Handling in Managed COBOL
*> Throw an exception
declare myException as type Exception =
new Exception(“Something is really wrong.").
raise myException
*> Catch an exception.
try
set y to 0;
compute x = 10 / y
catch myException *> Argument is optional, no "When" keyword
display myException::Message
finally
invoke type Microsoft.VisualBasic.Interaction::Beep
end-try
Exception Handling in C#
// Throw an exception
Exception up = new Exception("Something is really wrong.");
throw up;
// 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();
}