Refactor exception handling

Ok, I sinned, I wrote too much code like this

try {
   // my code
} catch (Exception ex) {
   // doesn't matter
}

Now I'm going to clean / reorganize this.

I am using NB 6.7, and code completion stops on the first write, adding all types of exceptions, etc. After I made the above code, NB does not give any more help.

Do you know a way to say that NB look at all types of exceptions again and make a proposal to handle them and re-execute the code?

+5
source share
4 answers

When you request a suggestion on how to handle exceptions ...

. , java .

  • , , .
  • - , "- ", , , ".

:

  • , .
  • ( RuntimeException Error) .

( ) , , - ( , ). , , , :

  • . ( , - ). . .
  • . , , , ( ).
  • IGNORE: .

java , , catch , ...


, . ( ):

  • , (: ): , ...
  • , , (, , ...)
  • .
+1

PMD , catch (PMD ). NetBeans, .

catch :

  • . NullPointerException, null.
  • ( ) .
+4

, catch-all "" , Netbeans , .

, , .

. , try , catch. .

Netbeans .

PS: , Netbeans (.. ) .

+3

, netbeans:

  • try/catch → eclipse
  • eclipse try/catch ( throw).

, .

Edit

RuntimeException. :

  • catch /
  • try/catch → eclipse
  • eclipse try/catch ( throw).
  • catch catch

RuntimeExceptions ( !).

,

try {
   Integer.parseInt("Force a RuntimeException");
   myInputStream.close();
} catch (Exception oops) {
   // catch both IOException and NumberFormatException
}

try {
   Integer.parseInt("Force a RuntimeException");
   myInputStream.close();
} catch (IOException oops) {
   // catch IOException
} catch (Exception oops) {
   // catch NumberFormatException
}

( Exception NumberFormatException, )

+1

All Articles