Take the 2-minute tour ×

how to get all Exceptions in a java application (have several classes and packages) in a place? Example: create a class be get all Exceptions on other application classes

share|improve this question
Didn't get you. you want to scan through classpath what are the available exception ? –  Jigar Joshi Jan 9 '12 at 6:48
please provide more details. do you want to catch all exceptions or just see what exception classes are available (only your packages or including java library)? are you talking about runtime and/or checked exceptions. –  axel Jan 9 '12 at 6:53
Exceptions are not the only things thrown. You can throw Errors and even Throwable or sub-classes (which are neither Errors nor Exception) –  Peter Lawrey Jan 9 '12 at 8:06

4 Answers 4

In your main class, you may have something like this:

try { } catch (Exception ex) { }

In your other classes, you should throw the exceptions, like:

public void example() throws Exception { }

If you throw the other classes' exceptions, you can deal with them just in the main class.

share|improve this answer
have you understood the question ?? whatdoes user986566 wants? –  Blaze-Core Jan 9 '12 at 6:55
I guess user986566 wants to deal with all the application exceptions in just one class. –  Ramon Saraiva Jan 9 '12 at 6:58


If all you methods throw exception to the main calling method then you can catch all exceptions.

The hierarchy of exception classes commence from Throwable class which is the base class for an entire family of exception classes, declared in java.lang package as java.lang.Throwable.

share|improve this answer

Why don't you simply have a class ExceptionHandler with 2 functions

void handleException(Exception e);
void handleThrowable(Throwable t);

and at every try{}catch(Exception e){} simply use ExceptionHandler.handleException(e);

To find out what Exception is being thrown, use instanceof

For eg.

if(e instanceof NullPointerException)
share|improve this answer

As other already indicated, one option is to put your main method in a try-catch block

public static void main( String[] args ){
    //regular main code
  } catch (Throwable e){
    //do exception handling

Another possibility is setting a default uncaughtExceptionHandler on the Thread(s) you are using with the Thread#setDefaultUncaughtExceptionHandler method.

Note that both solutions only allow you to 'handle all exceptions in one place' if they don't get caught at other locations in your application

share|improve this answer

Your Answer


