Re: Why does Java require the throws clause? Good or bad language
design? (fwd)
Bobsparks@excite.com wrote:
I believe the main rationale after the portability, behind java is to
protect programmers from themselves and other programmers. The
original "C" style contract is easy to break or worse forget.
Therefore Java enforces you to at least catch any exception as a
generic Exception. I usually just Catch everything as an Exception
later if the business rules require two sorts of handling, IE inform
the user they must not supply zero or the DBA admin the database is
full then you can always use instanceof to cast back to some specific
behaviour. Original developers dream up all kinds of custom
exceptions usually though all it means is you are screwed and need to
log a message. Thankfully every exception can be cast to an Exception
and the reported with toString.
or getMessage(), or a combination of getMessage() and getStackTrace(), the
first fed to a logger.error() and the second to a logger.debug().
It is a bit sloppy to catch Exception instead of the particular checked
exceptions that a method can throw.
- Lew