aspose file tools*
The moose likes Beginning Java and the fly likes Rethrowing the same exception Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Spring in Action this week in the Spring forum!
JavaRanch » Java Forums » Java » Beginning Java
Bookmark "Rethrowing the same exception" Watch "Rethrowing the same exception" New topic
Author

Rethrowing the same exception

Andrew Parker
Ranch Hand

Joined: Nov 12, 2001
Posts: 178
Hi,
I have just gone through the Exception Handling chapter and found don't understand when should I use the rethrowing of same exception?
e.g.
catch(NullPointerException e) {
e.printStackTrace();
throw e;
}
aminur rashid
Ranch Hand

Joined: Sep 21, 2001
Posts: 79
Hi
Suppose a function A() calls another function B() and the exception is thrown in function B>now
when u say throw e( any exception) control is passed to the catch block of function A() else if u don say throw e then contol willl pass to the next command in function A() after the function B() is called


Regards<br />Aminur
Valentin Crettaz
Gold Digger
Sheriff

Joined: Aug 26, 2001
Posts: 7610
Maybe in some circumstances you need to catch an exception to present some error message to the user, to do some clean-up or anything else and then you still need to rethrow the same exception further to the calling method because of contract requirement or because you simply want the caller method to know what happened.


SCJP 5, SCJD, SCBCD, SCWCD, SCDJWS, IBM XML
[Blog] [Blogroll] [My Reviews] My Linked In
Dave Vick
Ranch Hand

Joined: May 10, 2001
Posts: 3244
Andrew
I closed the other thread you had with the same name because you asked basically the same question twice.
In the future you can use the edit feature ( to edit your previuos post instead of creatng a new one. Besides, most people will think it is an exact duplicate if they have the exact same name and not read them both anyway.


Dave
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Rethrowing the same exception