File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
The moose likes Programmer Certification (SCJP/OCPJP) and the fly likes Whats the point? Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Certification » Programmer Certification (SCJP/OCPJP)
Bookmark "Whats the point?" Watch "Whats the point?" New topic

Whats the point?

Amit Batra
Ranch Hand

Joined: Mar 04, 2006
Posts: 361
Whats the point of rethrowing an exception from a catch block when it cant be handled by other catch blocks. And if the exception rebounds back to the calling method, isnt a JVM shutdown then inevitable?
Theodore Casser
Ranch Hand

Joined: Mar 14, 2001
Posts: 1902

If the exception rebounds back to the calling method, it isn't inevitable that you're going to have a JVM shutdown - there are times when I'm programming that the "proper" response is to kick the message back a step to let the calling method deal with the matter. For instance, when I'm writing a utility class for large portions of an app, I'm going to want to handle any issues that arrise in different ways depending on what's happening at the moment when it was called, rather than having a single standard method. Perhaps in one spot it's appropriate to stop processing, while at others it's more appropriate to simply flag a warning and continue.

As for the point of rethrowing the exception, again, sometimes there's other things you're going to want to do with the thrown exception, after initially dealing with it. (At my office, for instance, we sometimes wrap our exceptions in another exception as we throw back to the calling method, to have a standard message appear for our users, while allowing us to see what was going on.)

Theodore Jonathan Casser
SCJP/SCSNI/SCBCD/SCWCD/SCDJWS/SCMAD/SCEA/MCTS/MCPD... and so many more letters than you can shake a stick at!
I agree. Here's the link:
subject: Whats the point?
It's not a secret anymore!