Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>This is an intractable problem.</p> <p>There is a relatively simple "non-solution". A static analyser should be able to enumerate all of the unchecked exceptions that are available in an application's class libraries; and all subclasses of any checked exception. Of course, that will give lots of false positives; i.e. exceptions that are allowed by the method signature, and yet cannot possibly be thrown in the call.</p> <p>To find out the exceptions that could really be thrown, you would need to analyse the code using some kind of bytecode or sourcecode manipulation framework. It should be possible to determine the set of exception classes of the classes that are mentioned in the closure of the Java methods that are possibly used in a given method call. However some exceptions are not mentioned in the Java code. This includes runtime exceptions and errors thrown by the JVM itself, and others that might be thrown by native code libraries. And there there is the possibility that exception throwing code could be injected at runtime; e.g. using dynamic proxies. Finally, you have the issue that some exceptions will only be thrown in circumstances that are provably impossible ... in a given application.</p> <hr> <blockquote> <p>So while I can learn in practice by catching java.io.Exception and printing out the actual exception, and then modifying code to handle that case, was wondering if there was a better method.</p> </blockquote> <p>Yea. A better method is to read the javadoc, use your common sense to figure out which exceptions are likely, and read the source code if you are in doubt.</p> <p>The other point is that you generally speaking don't need to know all of the possible exceptions in order to handle them effectively.</p> <p>Finally, since the actual exceptions thrown may vary from one JVM to another (these are implementation details!) it is a bad idea to make assumptions in your code about exactly what exceptions might be thrown.</p>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. VO
      singulars
      1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload