[ale] OT: java filereader question

Kevin Krumwiede kjkrum at comcast.net
Sat Apr 10 23:50:48 EDT 2004


On Thu, 8 Apr 2004 22:05:59 -0400 (EDT)
"J.M. Taylor" <jtaylor at onlinea.com> wrote:

> Where can I read something that explains decently what's going on with
> 
> exceptions, do you know?  It's certainly not a concept I'm familiar
> with, and everything I read just says "do this to catch an exception"
> which doesn't tell me _what_ I'm trying to do, or why, or what's
> actually going on when I do it.

Exceptions are a mechanism for enforcing error checking at compile time,
instead of having methods return error codes and just hoping you'll
check for them.  When an exception is thrown, the method that threw it
returns immediately to its caller.  If the caller doesn't handle it,
then it returns immediately to its caller, and so on.  Normal execution
resumes at the first 'catch' block that handles the given type of
exception.  If method A calls another method that might throw an
IOException, and method A doesn't handle it, then method A has to
declare that it might also throw an IOException.

Exceptions are objects just like any other, and they obey the same rules
of inheritance.  All exceptions are derived, directly or indirectly,
from java.lang.Exception.  If you want to define special error
conditions, you can create your own exception classes.  A catch block
for a particular exception will also catch any subclasses.

Krum



More information about the Ale mailing list