File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
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
JavaRanch » Java Forums » Java » Beginning Java
Bookmark "Rethrowing the same exception" Watch "Rethrowing the same exception" New topic

Rethrowing the same exception

Andrew Parker
Ranch Hand

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

Joined: Sep 21, 2001
Posts: 79
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

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.

[Blog] [Blogroll] [My Reviews] My Linked In
Dave Vick
Ranch Hand

Joined: May 10, 2001
Posts: 3244
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.

I agree. Here's the link:
subject: Rethrowing the same exception
It's not a secret anymore!