*> 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
end-try
import java.lang.*; // Throw an exception Exception up = new Exception("Something is really wrong."); throw new EmptyStackException(); // Catch an exception try { int y = 0; int x = 10 / y; } catch (ArithmeticException ex) // Argument optional, no "When" keyword { System.out.println(ex.getMessage()); } finally { System.out.println("\007"); }
Portions of these examples were produced by Dr. Frank McCown, Harding University Computer Science Dept, and are licensed under a Creative Commons License.