A good question is never answered. It is not a bolt to be tightened into place but a seed to be planted and to bear more seed toward the hope of greening the landscape of the idea. John Ciardi
Holla at me...<br /><a href="http://codeforfun.wordpress.com" target="_blank" rel="nofollow">http://codeforfun.wordpress.com</a>
Originally posted by amol deshpande:
...
We have a few options to work over this.
1) If we keep all innermost layer exceptions as those are, it explodes exception handlers all over the system.
Originally posted by amol deshpande:
2) We can create wrapper check exceptions , ex. AppConnectionException which may denote connection problem to higher layer, and may contain root cause denoting actual problem, viz, SQLException, NamingException, RemoteException, etc.
Even with this approach, the system floods exception handlers all over.
Originally posted by amol deshpande:
3) Third approach is to define a runtime exception specific for an application, which would wrap the checked exception underneath and at the highest level catch this exception and report to the user or take some action.
Something like
try{
rs.executeQuery(getRemoteQuery());
}catch(SQLException e)
{
throw new ProductQueryException(e); // an unchecked exc.
}catch(RemoteException e)
throw new ProductQueryException(e);
}
As a result of this its callers (which may be too many, as its lowermost layer code) do not need to handle ProductQueryException, only highest layer can put this in try catch and treat in a way.
You only have to handle the exception where you call the method. You don't complain about having to call the method so whycomplain about having to catch the exception?
There are NO pros to masking an exception because you don't feel like catching it. If there is nothing that you can do with the exception on a certain layer, then let that layer decide to ignore it. But don't change the lower layer to not >throw an exception just because the upper layer does not feel like catching exceptions!?!
Checked exceptions seem like a really good idea at first. But it's all based on our unchallenged assumption that static type checking detects your problems and is always best. Java is the first language (that I know of) that uses checked exceptions and is thus the first experiment. However, the kind of code you must write around these things and the common phenomenon of "swallowed" exceptions begins to suggest there's a problem. In Python, exceptions are unchecked, and you can catch them and do something if you want, but you aren't forced. And it seems to work just fine.
A good question is never answered. It is not a bolt to be tightened into place but a seed to be planted and to bear more seed toward the hope of greening the landscape of the idea. John Ciardi
Nothing up my sleeve ... and ... presto! A tiny ad:
Smokeless wood heat with a rocket mass heater
https://woodheat.net
|