Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Audit Java: system to detect exceptions thrown / caught (aop?)

Due to checked exceptions, we can have some problems in production having all exceptions caught in the right place and logged correctly.

I wonder if there is some opensource tool to help with auditing these problems.

For example, is there some AOP tool that would intercept all exceptions thrown and see if they are re-thrown, wrapped or logged? This would help identify the bad catches.

like image 723
Sebastien Lorber Avatar asked Dec 09 '10 14:12

Sebastien Lorber


People also ask

What happens when exception is thrown in Java?

When an exception is thrown using the throw keyword, the flow of execution of the program is stopped and the control is transferred to the nearest enclosing try-catch block that matches the type of exception thrown. If no such match is found, the default exception handler terminates the program.

What is an exception how the exceptions are handled in Java?

Java Exception Handling is a mechanism to handle runtime errors such as ClassNotFoundException, IOException, SQLException, RemoteException, etc. Exception is an unwanted or unexpected event, which occurs during the execution of a program, i.e. at run time, that disrupts the normal flow of the program's instructions.

How do you throw a caught exception?

Using the Throws keyword Throws is a keyword used to indicate that this method could throw this type of exception. The caller has to handle the exception using a try-catch block or propagate the exception. We can throw either checked or unchecked exceptions.


1 Answers

If you've decided that you would like to take the AOP route, the Spring Framework provides an easy to use AOP framework. Essentially, like much of Spring, you would use a combination of a xml config file and some java code to define the AOP functionality you are looking for.

In your case, I believe you would be looking to define an 'After Throwing Advice', in which you would of course have access to the exception thrown.

A good place to start in terms of documentation is the AOP Chapter in the Spring docs: http://static.springsource.org/spring/docs/2.5.x/reference/aop.html

Oh, and I believe all Spring projects are open source as well =)

like image 64
Kai Avatar answered Sep 18 '22 19:09

Kai