Java – can I find all (checked) exceptions that might be thrown in groovy code blocks?

I'm maintaining a groovy application that must have substandard error handling - countless catch instances (exception E) {} all over the place I want to implement finer grained exception handling, but in order to do this, I need to know which exceptions a given handler block can catch - and because groovy does not follow the exception rules of Java checking, this is very important

If I have a powerful test platform, I will delete all the handlers and test it until I have a comprehensive method to cover - but unfortunately, this code is part of a rather chaotic distributed application, mainly in production and relying on custom hardware, Therefore, creating a test platform for it is a larger task than the resources I currently have

So, I wonder if there is any shortcut (a specific ide with the right magic, or even) through which I can analyze the code and get a list of all possible exceptions that may be thrown by a given attributive sentence?

Solution

If you can assume that all instances of catch (exception Ex) {} are placed there because they are migrated from Java code (when programmers are too lazy to deal with them) and programmers never intend to continue the process, you should only be able to replace all instances of that generation with the following code:

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

If not, I don't know how to effectively change the code base without knowing how it should work (or let the test know how it should work) Even if there is a tool to enumerate all possible exceptions, how do you know what to handle and what to re throw without knowing how the application's intention fails?

The content of this article comes from the network collection of netizens. It is used as a learning reference. The copyright belongs to the original author.
THE END
分享
二维码
< <上一篇
下一篇>>