Can I find all (marked) exceptions that can be thrown in a Groovy code block?

I do the maintenance in a Groovy application that has explicitly non-standard error handling - lots of catch (Exception e) {} instances all over the place. I want to implement much finer-grained exception handling, but for this I need to know what exceptions a given handler block can expect to catch, and since Groovy does not comply with Java's exception-checking rules, it is trivial.

If I had a reliable testing platform for this application, I would simply delete all the handlers and then check them until I have an exhaustive list of the ways in which it can fall, but, unfortunately, this code is part of a rather dirty distributed an application that exists mainly in production and depends on the user equipment, so creating a test bench for it is a much bigger task than I currently have resources for.

So, I am wondering if there is any shortcut (a specific IDE with the correct magic, even), with which I can analyze the code and get a list of all possible exceptions that this operator can throw?

+4
source share
1 answer

If you can assume that all catch (Exception ex) {} instances were put there because they were ported from Java code (when the programmer was too lazy to handle them) and the programmer never wanted the thread to continue, you It should just be possible to replace all instances of this code:

 catch (Exception ex) { throw new RuntimeException(ex); } 

Other than this, I don’t see how you are going to effectively change the code base without knowing how it should work (or have tests that know how it should work). Even if there was a tool for listing all possible checked exceptions, how would you know which ones to handle and which ones to re-throw without knowing how the application should crash?

+1
source

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


All Articles