Hi Everybody, I just registered in the Javaranch. But I have been viewing it for last Month. I am planning to take exam in a week; I have a basic doubt about Exceptions and Errors can any body tell me what is basic difference between an Exception and an Error, try to explain me in an elaborated way. And is there any way, so that we can identify at seeing the code whether it will give an Compile time error or run time error, are there any thumb rules. Please help me.
shanks iyer
Ranch Hand
Joined: Oct 16, 2000
Posts: 47
posted
0
Hi Narra, If i put it simply errors are fatala and exceptions can be caught and recovered from, the detailed explanation is listed below: Errors and exception in java are derived from the java.lang.throwable class. And this is a super class to two other sub classes called error and exception The exceptions catered in the java.lang.error are for eg something like thread death or some problem in jvm these are never genrally caught in the program coz they are irrecoverable,i mean they cannot be tackled in the program coz the program abnormally ends.And Exceptions are subclasses of java.lang.exception which define various exceptions like runtime exception,i/o exception etc.In And exceptions can be further classifyed in to two types checked and unchecked, checked exceptions are those which the method declares and handles them like for eg suppose some method is peforming an i/o operation so there could be an exception like file not found so the method declares this exception and handles it using the try catch block such kind of exceptions are checked exceptions. Unchecked exceptions are those like runtime exceptions an eg of unchecked exception couldbe arthematic exception which occurs when you attempt to divide by zero so it is the programmer's reponsiblity to see to it such situations dont arise in the program.And for further good reading you can refer to khalid's book hope this clear your doubt. Regards, Shankar. [This message has been edited by shanks iyer (edited November 02, 2000).]