Possible Duplicate:
Is it a bad practice to catch the Throwable?
Is it best practice to catch throwable? If catching throwable, will it catch out of memory etc exception?
Possible Duplicate:
Is it a bad practice to catch the Throwable?
Is it best practice to catch throwable? If catching throwable, will it catch out of memory etc exception?
The only way to catch Throwable
exception, is the same as that you catch Exceptions. How it works is, it catch the exceptions/error by the hierarchy tree.
So if you wanna catch OutOfMemory
Error you have some options:
try{
}catch(java.lang.OutOfMemoryError t){
}
try{
}catch(java.lang.Error t){
}
try{
}catch(java.lang.Throwable t){
}
Just check the class tree in the docs for the exception that you wanna catch. http://docs.oracle.com/javase/6/docs/api/java/lang/OutOfMemoryError.html
Also a good practice is among your catch blocks always start with the ones with are in the bottom of the tree, so for example:
try{
//
}catch(java.lang.OutOfMemoryError t){
// handle out of memory error
}catch(java.lang.Throwable t){
// handle other throwable
}
Also remember that Error and Exception they both extend Throwable, but they dont extend each other so both are siblings in the class tree.