File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
The moose likes Beginning Java and the fly likes exception handling Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of EJB 3 in Action this week in the EJB and other Java EE Technologies forum!
JavaRanch » Java Forums » Java » Beginning Java
Bookmark "exception handling" Watch "exception handling" New topic
Author

exception handling

aditya kumar
Greenhorn

Joined: Apr 02, 2008
Posts: 12
How can I throw an exception without declaring it in a 'throws' clause?
Joanne Neal
Rancher

Joined: Aug 05, 2005
Posts: 3169
    
  10
Throw an exception that extends RuntimeException


Joanne
Gavin Tranter
Ranch Hand

Joined: Jan 01, 2007
Posts: 333
Are you really sure you wnat to throw an unchecked exception?

Would an Error be better?

I have to admit to feeling exceptions are used rather to much in Java, that sometimes what is an Exception actual should be an Error cos there is no way to recover from it. But I do not agree with C# method of no checked exceptions.

Check out the Java Tutorial on Exceptions, heres a discussion of Unchecked Exceptions, from the Exception tutorial.

Gavin
Peter Chase
Ranch Hand

Joined: Oct 30, 2001
Posts: 1970
Originally posted by Gavin Tranter:
Are you really sure you wnat to throw an unchecked exception?

Would an Error be better?


Throwing Errors is very rarely a good idea, and certainly not something for beginners to do.

The idea of the distinction between RuntimeException and Error is that the former is evidence of a bug in a specific piece of code, whereas an Error is evidence of a JVM-wide problem. Examples: -

NullPointerException typically means that a particular thread has encountered a bug in a particular piece of code. But it might well be possible, and sometimes appropriate, for other threads to carry on running other pieces of code.

But OutOfMemoryError means that the whole JVM has run out of memory, and is in a state where data may be inconsistent. There is no way that any useful work can be done, once this has happened, and the only valid action is to try to close down the application as gracefully as possible.


Betty Rubble? Well, I would go with Betty... but I'd be thinking of Wilma.
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: exception handling
 
Similar Threads
counting algorithm
Java ranch rules roundup
void return type in JSP expression
why JMX can not stop
WA #1.....word association