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 Unchecked Exception Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » Beginning Java
Bookmark "Unchecked Exception" Watch "Unchecked Exception" New topic
Author

Unchecked Exception

Brian Smith
Ranch Hand

Joined: Oct 26, 2002
Posts: 232
Hello,
I tried to search explanations on Unchecked Exception (sub class of Runtime Exceptions) but could not find the one that made my understanding clear. I would apprecieate if someone could explain me WHY runtime exceptions are unchecked. All the time I get definitions that Runtime Excpeptions are not checked by compiler while compiling the codes. BUT WHY?

Also, how does an Error differ from an Exception?

Thanks.
Steve McCann
Ranch Hand

Joined: Oct 20, 2004
Posts: 81
Hi
As the name implies, a RuntimeException is one which occurs at run time. The compiler cannot check for these as variables have not been assigned values yet - you may be dividing by zero for example.

You can handle them if you want, if you divide by zero it might be helpful to have an elegant way of dealing with it.

An Error is a subclass of Throwable (so is Exception) and is used when the JVM has a serious error which should not be caught.

Steve
Nicky Eng
Ranch Hand

Joined: Mar 26, 2005
Posts: 378
Steve is right. The error and Exception are the subclasses of Throwable.

if you have the K&B book, you can go to page 245 (figure 4-2) hierarchy diagram.

RuntimeException is unchecked exception, so is Error.

All other exceptions(under Exception class), meaning all those that do not derive from java.lang.RuntimeException, are checked exceptions. A checked exception MUST be caught somewhere in your code. that means that unchecked exceptions you dont have to caught it in your code,but if you want to also can.

correct me if i'm wrong....thanks in advance.
[ June 28, 2005: Message edited by: Nicky Eng ]

From NickyEng
Diploma in Computer Studies
SCJP 1.4
SCWCD 1.4
Formula 1 app by Maxis (Playbook)
Manuel Moons
Ranch Hand

Joined: Mar 05, 2002
Posts: 229
A RuntimeException is not an Error.

There are 3 types of exceptions:

Checked exceptions --> these must be caught or compilation will fail.
Unchecked exception --> these can be caught but the compiler will not complain if they are not caught.
Errors --> These can not be caught because these exceptions will indicate that there is a serieus problem eg. OutOfMemoryError indicates that there is no more memory available and so normal flow cannot continue.
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Unchecked Exception
 
Similar Threads
exceptions
Exception Handling
How to recognise a checked or unchecked exception
what is the difference between checked and unchecked exceptions
Exception Doubt