简体   繁体   中英

How to find exceptions that were “ignored”?

No need to declare checked exceptions in throws clause or handling them in try/catch block in scala is the feature that I love. But it can be a problem when exception must be handled but was ignored. I'm looking for tools (maybe compiler flag/plugin) to find methods that ignored checked exceptions.

One option is catch the exception at a very high level of you application (The top would be the main -method).

Another option would be to use an UncaughtExceptionHandler (if you are on a JVM):

object MyUncaughtExceptionHandler extends Thread.UncaughtExceptionHandler {
  def uncaughtException(thread: Thread, throwable: Throwable) {
    println("Something bad happened!")
  }
}

val t = new Thread(new Runnable {
  override def run() {
    null.toString
  }
});

t.setUncaughtExceptionHandler(MyUncaughtExceptionHandler)
t.start()

AFAIK, there is no such tools, however one technique I've used successfully is to simply install an at-throw-point break point in your IDE (IntelliJ or Eclipse) for java.lang.Throwable which will pause execution at throw point of every java exception (or error) as the program runs and then to keep hitting "play" to see them all (at least on the path of execution you're interested in)

Cheers...

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM