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?
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.
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 ]
Diploma in Computer Studies
Formula 1 app by Maxis (Playbook)
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.