How to find exceptions that have been "ignored"?

No need to declare checked exceptions in the throws clause or handle them in a try / catch block in scala, this is a function that I love. But this can be a problem when an exception needs to be handled, but it is ignored. I am looking for tools (possibly a compiler flag / plugin) to find methods that ignored checked exceptions.

+6
source share
2 answers

One of the options is an exception at a very high level of your application (the upper part will be the main method).

Another option is to use UncaughtExceptionHandler (if you are on the 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() 
0
source

AFAIK, there are no such tools, however, one of the methods that I have used successfully is simply to set the breakpoint of the access point in your IDE (IntelliJ or Eclipse) for java.lang.Throwable, which pauses execution to throw every Java exception ( or errors) as the program starts, and then continue to β€œplay” to see them all (at least in the way of execution that interests you)

Greetings ...

0
source

Source: https://habr.com/ru/post/890220/


All Articles