The most common reason is probably to log it, perhaps adding some useful information, and maybe rethrowing it afterwards, especially if it's an Error.
When you do this, you can't be sure that any of the code in the catch block will really execute, because it's possible that the problem is so bad that your code will immediately throw another error and leave the catch block. But I usually figure it's better to try to log the problem and fail, rather than not even try.
Specific exceptions and errors may have specific workarounds (yes even Errors, sometimes at least) so you can catch them and handle them - but in this case you probably shouldn't catch Throwable or catch Error, but rather catch the specific type of Throwable that you have a workaround for.
Whenever you're catching an Error or Throwable (including Error),
you should think carefully about the consequences. Generally for beginners you simply should not do this. But with more experience you may be able to determine if circumstances warrant catching the error. Generally you should consider: what's the worst thing that can happen if you don't catch it? What's the worst that can happen if you
do catch it? Often letting the JVM crash is best thing to do, and restart it - either immediately, or after you've analyzed and fixed the problem.
Note also that letting an Error go uncaught does not necessarily stop the JVM, especially if there are multiple threads involved. And sometimes it may not even get printed to the screen, depending on the environment you're using. Try putting throw new Error("test") in your code to see what effect it has, if you're not sure.
As for catching unchecked exceptions, that's much more reasonable. It's true that those often (not always) signal a programmer error that a programmer will have to fix. But for many applications, it's still reasonable to keep running the program. Let's say you're processing a payroll for all employees, and a few of the employees have left their middle name blank (perhaps they don't have a middle name), causing a NullPointerException. Should you not process
any employees because
some throw exceptions? I think probably you should try to process all of them, and fix problems for the remaining employees as soon as possible. For example:
[ March 03, 2008: Message edited by: Jim Yingst ]