File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
The moose likes Beginning Java and the fly likes Class Exception Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » Beginning Java
Bookmark "Class Exception" Watch "Class Exception" New topic

Class Exception

Vasco Dion�sio

Joined: Dec 04, 2003
Posts: 22
Hi there,
I could use some help, please?
Here goes the code first and my problem after:
public void doSomething() throws IOException, Exception {
try {
//do something that throws an unknow exception (not IOException)
} catch (IOException e) {
throw e;
} catch (Exception e) {
throw e;
} finally {
When I call doSomething() an error occurs and the only output I see is:
finally. Shouldn't I always see the output
no matter what exception is thrown? Isn't Exception the SuperClass of all Exceptions?
Thanks a lot
[ January 14, 2004: Message edited by: Vasco Dion�sio ]
Ernest Friedman-Hill
author and iconoclast

Joined: Jul 08, 2003
Posts: 24189

Exception is the superclass of all Exceptions, but Throwable is the superclass of Exception and Error, the two main categories of exceptions (note that I
used the lowercase word "exceptions.") Error includes things like OutOfMemoryError, StackOverflowError, ArithmeticError, etc; they're unchecked, like RuntimeExceptions, but they correspond to VM errors rather than to programmer errors per se.
If you change the "Exception" to "Throwable", I believe you'll see the printout from that block.

[Jess in Action][AskingGoodQuestions]
Vasco Dion�sio

Joined: Dec 04, 2003
Posts: 22
First off all thanks for your answer...
You were right... it worked. Furthermore do you know the diference between Errors and Exceptions. Why do they exist both?
Thanks again
Maarten Vergouwen
Ranch Hand

Joined: Jan 12, 2004
Posts: 60
An Error is something that shouldnt happen, and if it does it is not something that you can do anything about once it happens. Things like 'out of memory' and stackoverflows are Errors.
Exceptions are things that can happen in a program, but that are not necessarily errors; they could well be the result of an entirely correct bit of logic. For example, 'File not found' is an exception, but wholly valid if your code was meant tot test for a file being present for example.
Likewise, when reading a file you often read until you get an 'end of file' exception, which means you can stop reading.
Some Exceptions _are_ errors, such as an Arithmetic exception. But these are things you can prevent in your code (ie checking a number to see if it's not 0 before dividing something by it).
[ January 14, 2004: Message edited by: Maarten Vergouwen ]
Vasco Dion�sio

Joined: Dec 04, 2003
Posts: 22
Thanks a lot... both of you.
jQuery in Action, 2nd edition
subject: Class Exception