Basic HTML version of Foils prepared 18 May 97

Foil 76 User Created Exceptions

From Java Tutorial - Spring 1997 Part II: Java Language and Object-Oriented Concepts Peking Tutorial, Web Certificate -- Spring-Summer 1997. by Nancy J. McCracken,Geoffrey C. Fox


1 Exception class has two constructors, one of which allows a message to be included in each instance.
2 The user can either throw an exception of type Exception with a unique message, or create own subclass of Exception:
3 public static void MyMethod() throws MyException
  • { . . .
  • throw new MyException;
  • . . . }
4 class MyException extends Exception
  • { public MyException ()
  • { super ("This is my exception message."); }
  • }
5 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.

in Table To:


© 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 Thu Jan 8 1998