Child pages
  • Adding a try-catch block
Skip to end of metadata
Go to start of metadata
  • This shows how to use Eclipse to insert a try-catch block around a statement which automatically includes possible exceptions
  1. Select the statement to surround with a try-catch block
  2. Right click on the selection and choose Source -> Surround with Try / Catch Block
  3. You should now edit the Auto-generated catch block(s)
    • Note: don't forget to remove the e.printStackTrace(); if you do not want this exception to put a stackTrace in the logs
  • No labels

1 Comment

  1. Best practice: propagate all exceptions that you don't know how to deal with as some kind of RuntimeException. You may choose to log them at source as well but this tends to make for somewhat noisy logs with the same exception occuring several times.

    Either use JDK 1.4+ "cause" system to wrap the original exception (you will need to select an existing exception type that will fill in "cause" or derive one yourself), or, even better, use the PonderUtilCore "UniversalRuntimeException" (delivered as part of RSF!) which guarantees never to do more than one level of wrapping.

    See Bruce Eckel at http://www.mindview.net/Etc/Discussions/CheckedExceptions
    See URE at http://www2.caret.cam.ac.uk/rsfwiki/Wiki.jsp?page=UniversalRuntimeException