a) All may be caught using try {...} catch () {...} syntax. // YES (assuming here ALL means Exception and RuntimeException as u said. Note Exception INCLUDES RuntimeException) b) Developers cannot create their own Error subclasses. //NO c) A RuntimeException must always be caught or declared as thrown by the method which raises it. //NO d) Non-RuntimeExceptions must always be caught or declared as thrown by the method which raises them. //YES (also called as CHECKED EXCEPTIONS) e) Errors must always be caught or declared as thrown by the method which raises them. //NO Now what do you think about the foll. code? Compile? Run? or Both? If runs successfully what do you think will bw printed? regds maha anna <pre> try{ throw new UnknownError(); }catch (UnknownError e) { System.out.println(e); }finally{ System.out.println("finally"); } System.out.println("END"); throw new UnknownError(); </pre>

[This message has been edited by maha anna (edited March 09, 2000).]

Divakar
Greenhorn

Joined: Mar 01, 2000
Posts: 25

posted Mar 09, 2000 22:16:00

0

This code compiles and while running error thrown at try block is caught by catch. All the confusion arised from the Sun java documentation for Errors. They have given "An Error is a subclass of Throwable that indicates serious problems that a reasonable application should not try to catch. Most such errors are abnormal conditions. The ThreadDeath error, though a "normal" condition, is also a subclass of Error because most applications should not try to catch it. "

AS you would see, that here it is also referring to errors. Sun recommends not to catch errors. So I would say 1 is false.

Originally posted by maha anna:a) All may be caught using try {...} catch () {...} syntax. // YES (assuming here ALL means Exception and RuntimeException as u said. Note Exception INCLUDES RuntimeException) b) Developers cannot create their own Error subclasses. //NO c) A RuntimeException must always be caught or declared as thrown by the method which raises it. //NO d) Non-RuntimeExceptions must always be caught or declared as thrown by the method which raises them. //YES (also called as CHECKED EXCEPTIONS) e) Errors must always be caught or declared as thrown by the method which raises them. //NO Now what do you think about the foll. code? Compile? Run? or Both? If runs successfully what do you think will bw printed? regds maha anna <pre> try{ throw new UnknownError(); }catch (UnknownError e) { System.out.println(e); }finally{ System.out.println("finally"); } System.out.println("END"); throw new UnknownError(); </pre>

[This message has been edited by maha anna (edited March 09, 2000).]

maha anna
Ranch Hand

Joined: Jan 31, 2000
Posts: 1467

posted Mar 10, 2000 17:43:00

0

What you say is correct.It is not a good idea to catch Error. Because they occur due to something seriously wrong happened. Practically it should not happen. If happens we have to address the problem. Instead we should not try to catch the Error. First of all you do not know when it will happen or in which line of code it will happen. Then where can we try to catch the Error ?(except trying to clutter the code..). But What I thought the intent of the qstn was whether we can/can not catch the Error (if at all we know where to catch). So I thought the answer is true. regds maha anna