- No there is no automatic technique
- Yes there is a manual techniques: You look at the definition of the reference: for .net component you see in comment the input args, return and exceptions susceptible to trigger, but this is manual approach that must be done on all targeted methods.
If your target code has undefined behavior, I suggest that you enhance your exception handling on time, and start with most generic exception in your first version.
You log the content of exception analyse what is it then add this new type of exception in your error handling.
in all the case if you let general exception in the end of catch you will catch everything and this is a current practice.
While your answer describes a method to handle the situation, it is not really an answer to the question. – Fildor
Yes it is an answer, do you know an automatic technique to list all Exceptions that can be triggered on a target code ?
But in existing code it might be pretty dangerous to remove a catch block that handles a specific exception in a specific way. – Chippen
Where do I suggest tor Remove a catch block ? If your target code already catches an exception, your caller code is not impacted by it as it will not see any exception, and there is no use to do this.
If however you see explicitly in the target code that an exception is triggered with static code analysis, and if you want to see how to trigger it, you can design a unit test and create a scenario with special input to specifically trigger the code path, and to expect the exception in the test definition.
In fact there is a problem of understanding between your question and my answer.
You want to ask.:
For a given exception type, is there a way to know that a given target code can throw this exception. Answer is you must analyse it manually or try to fuzz.
My initial answer target another question which would be: for a given target code is it possible to know all exceptions that could be triggered.