Basic HTML version of Foils prepared 9 Sept 1997

Foil 49 User Created Exceptions

From Java to be used in (Scientific) Computing Part II: Java Language and Object-Oriented Concepts Basic Simulation Track for Computational Science CPS615 -- Fall Semester 97. by Nancy J. McCracken,Geoffrey C. Fox


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 Sun Feb 22 1998