code_junkie

How do I recover from an unchecked exception?

Nov 10th, 2011
109
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.52 KB | None | 0 0
  1. try {
  2. throw new IllegalArgumentException();
  3. } catch (Exception e) {
  4. System.out.println("boom");
  5. }
  6.  
  7. // insert the user
  8. try {
  9. hibernateSession.save(user);
  10. } catch (ConstraintViolationException e) {
  11. throw new MessageException("Username " + user.getName() + " already exists. Please choose a different name.");
  12. }
  13.  
  14. try {
  15. ... render the page
  16. } catch (MessageException e) {
  17. ... render a nice page with the message
  18. } catch (Exception e) {
  19. ... render "we logged your problem but for now you're hosed" message
  20. }
Add Comment
Please, Sign In to add comment