JPittard
JPittard

Reputation: 655

Finding All Unchecked Exceptions in My Code

I'm working on a Java project, and am trying to ferret out all unchecked exceptions which I might not have noticed and failed to handle. So far I've been handling them one at a time as they occur, but before the project is released I'd like to know, definitively, that they all have handler blocks. Is there any tool - a FindBugs setting, an IDE feature or plugin, etc - that can simply display them all for me? Google is proving fruitless, with simply a bunch of pages explaining the difference between checked and unchecked exceptions.

Upvotes: 0

Views: 99

Answers (2)

Kong
Kong

Reputation: 9546

There are 1,000's of unchecked exceptions in the JDK. For example have a look at java.util.List#add, 4 unchecked exceptions just there. You can't catch them all!

What you can do though is layer your application, then add a more generic try/catch of RuntimeException into your higher layers. This code could do things like logging the exception and maybe turning the exception text into an error message to be displayed.

Upvotes: 3

peter.petrov
peter.petrov

Reputation: 39437

Find all custom (app-specific) exceptions which extend RuntimeException. Make them extend something else e.g. Exception123 where Exception123 is checked and is something you for sure don't handle in your code already. You'll now get compile errors which will show you the locations of the unchecked exceptions you don't handle in your code.

And if your code is using non-custom (i.e. built-in) unchecked exceptions then you just need to know their type names, and search for them in your codebase. Otherwise, I don't see how you can automate the process of finding these.

Hope this helps at least partially.

Upvotes: 0

Related Questions