Win a copy of Mesos in Action this week in the Cloud/Virtualizaton forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Error Handling....Confusion

 
shesh anand
Greenhorn
Posts: 29
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 29
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 320
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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!
 
shesh anand
Greenhorn
Posts: 29
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic