Basic HTML version of Foils prepared Sept 21 1998

Foil 46 User Created Exceptions

From Java Tutorial 98- 2: Java Language and Object Oriented Techniques NAVO Tutorial -- Sept 23 1998. by Geoffrey C. Fox, Nancy McCracken

Exception examples for Foil 46
Exception class has two constructors, one of which allows a message to be included in each instance.
The user can either throw an exception of type Exception with a unique message, or create own subclass of Exception:
  • public static void MyMethod() throws MyException
  • { . . .
  • throw new MyException;
  • . . . }
  • class MyException extends Exception
  • { public MyException ()
  • { super ("This is my exception message."); }
  • }
Methods which call "MyMethod" should use a try and catch block which catches an exception e of type MyException. Methods e.getMessage and e.printStackTrace can be used on Exceptions.



© Northeast Parallel Architectures Center, Syracuse University, npac@npac.syr.edu

If you have any comments about this server, send e-mail to webmaster@npac.syr.edu.

Page produced by wwwfoil on Sat Nov 28 1998