| Author |
Error Handling....Confusion
|
shesh anand
Greenhorn
Joined: Feb 10, 2007
Posts: 29
|
|
please clarify...what is it that i have done below and if it's Handling the error...so please justify...i am a bit confused...cause there are compile time errors and runtime errors....asynchronous and Synchronous ones...damn them..what i want to get clarified is below class HandleError { public static void show() throws Error { throw new Error; } } public class ErrorHandled { public static void main(String args[]) { try{ HandleError.show(); }catch(Error er) { System.out.println("Error Handled "+er); } } Although i have thrown the instance of Error explicitly...but the what or throw is used for... i mean i am confused
|
 |
shesh anand
Greenhorn
Joined: Feb 10, 2007
Posts: 29
|
|
please clarify...what is it that i have done below and if it's Handling the error...so please justify...i am a bit confused...cause there are compile time errors and runtime errors....asynchronous and Synchronous ones...damn them..what i want to get clarified is below Ok Corrected version class HandleError { public static void show() throws Error { throw new Error(); } } public class ErrorHandled { public static void main(String args[]) { try{ HandleError.show(); }catch(Error er) { System.out.println("Error Handled "+er); } } Although i have thrown the instance of Error explicitly...but then what for throw is used for... i mean i am confused
|
 |
Bob Ruth
Ranch Hand
Joined: Jun 04, 2007
Posts: 318
|
|
The first thing I would do is go lookup throw() and make sure that you know what it is designed to throw. Hint... what is Error that you are throwing? What kind of "thing" is it? Once you find that, I think you will get to the bottom of the problem because the catch block will have to catch the same thing (or a superclass of it!). Ooooooops.... another hint. Good luck!
|
------------------------
Bob
SCJP - 86% - June 11, 2009
|
 |
shesh anand
Greenhorn
Joined: Feb 10, 2007
Posts: 29
|
|
|
Either you didn't get me or i didn't...what i mean to say is that...as we have read that error can't be handled...but in above code...IS Error is handled ???...if not then what it is...or i am conceptually on the wrong path...clarify...and its Error()...no AWTError() or anything like that.
|
 |
 |
|
|
subject: Error Handling....Confusion
|
|
|