Null pointer exception catching Tool



  • Is there is any tool to capture all the null pointer exception in the java project? Am working in the mobile application testing, during my testing I have noticed so many null pointer exceptions which are not captured properly during the implementation.

    Anyone suggest me the best tool in the online to capture the null pointer exception



  • The cleanest way is to create an aspect before the Exception is thrown and deal with it:

    public aspect ExceptionLoggingAspect {
    
        before (NullPointerException e): handler(Exception+) && args(e) {
            System.err.println("Caught by aspect: " + e.toString());
            e.printStackTrace();
        }
    }
    

    More details here.

    The alternative is not change the code every time you see a NPE...

    (You don't want to do this...)



Suggested Topics

  • 2
  • 2
  • 2
  • 2
  • 2
  • 2
  • 2
  • 2