• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

Class Exception

 
Greenhorn
Posts: 22
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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) {
System.out.println("IOException");
throw e;
} catch (Exception e) {
System.out.println("Exception");
throw e;
} finally {
System.out.println("finally");
}
}
When I call doSomething() an error occurs and the only output I see is:
finally. Shouldn't I always see the output
Exception
Finally
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 ]
 
author and iconoclast
Posts: 24207
46
Mac OS X Eclipse IDE Chrome
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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.
 
Vasco Dion�sio
Greenhorn
Posts: 22
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hello,
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
 
Ranch Hand
Posts: 60
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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
Greenhorn
Posts: 22
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Thanks a lot... both of you.
 
reply
    Bookmark Topic Watch Topic
  • New Topic