If doSomething (for example, doSomething() throws IOException ) does not have a throws statement), any exceptions that will occur will be an instance of RuntimeException . If you want to know the exact exception class thrown by doSomething , you can always try
try { doSomething(); } catch (RuntimeException e){ System.out.println(e.getClass().getName()); }
Knowing which runtime exceptions may be thrown without actually running the program is difficult. Even if none of the codes called by doSomething() has an explicit throw, java kernel operations can always throw a NullPointerException , ArrayIndexOutOfBoundsException , etc. With the wrong entry. Here are some ideas:
- Pass by hand. At least you will learn some of the exceptions.
- Use reflection to find any expression statements available from
doSomething . - Run the test cases and write down the exceptions mentioned above. Good tests will reveal important errors that should be prepared for
doSomething . - Go to the people who first laid the trick
In any case, it is generally best to catch exceptions that are as specific as possible, because you donβt know exactly what went wrong when you try to deal with all the cases in one sentence.
tb189
source share