Java Throwing Exceptions
Java Throwing Exceptions.
-
We can throw our own exceptions on:
- either instances of Exception,
- one of its existing subclasses, or
- our own specialized exception classes
... class SecurityException extends Exception { SecurityException() { super(); } SecurityException( String desc ) { super( desc ); } } ... public void checkRead( String s ) { if ( new File(s).isAbsolute( ) || (s.indexOf("..") != -1) ) throw new SecurityException("Access to file : "+ s +" denied."); } ...
- In this case, we throw in our method an SecurityException, which we earlier have created.
© 2010 by Finnesand Data.
All rights reserved.
This site aims to provide FREE programming training and technics.
Finnesand Data as site owner gives no warranty for the
correctness in the pages or source codes.
The risk of using this web-site pages or any program
codes from this website is entirely at the individual user.