If you want, you can add throwing suggestions to your methods. Then you do not need to immediately check proven methods. This way you can catch exceptions later (perhaps at the same time as other exceptions ).
The code looks like this:
public void someMethode() throws SomeCheckedException {
You can then deal with exceptions if you do not want to deal with them in this method.
To catch all the exceptions that a block of code can block, you can do: (This will also catch the exceptions that you wrote yourself)
try { // exceptional block of code ... // ... } catch (Exception e){ // Deal with e as you please. //e may be any type of exception at all. }
The reason it works is because Exception is the base class for all exceptions. Thus, any exception that can be thrown is an Exception (upper case "E").
If you want to handle your own exceptions, first just add a catch before the generic Exception.
try{ }catch(MyOwnException me){ }catch(Exception e){ }
jjnguy Jul 02 '09 at 18:20 2009-07-02 18:20
source share