Take the 2-minute tour ×
Programmers Stack Exchange is a question and answer site for professional programmers interested in conceptual questions about software development. It's 100% free, no registration required.

This question already has an answer here:

My buddy told me today that some programmers transform a checked exception (e.g. EJBException, SQLException...) to an unchecked (RuntimeException?)

My buddy explained a call stack where if you change the bottom of the stack you would have to change every method that calls it if you change the bottom (innermost) method.

Can you elaborate and/or examplify with code more in detail or did I misunderstand something? I don't think that I have had that problem since I never wrote throws.

share|improve this question

marked as duplicate by gnat, MichaelT, Kilian Foth, m3th0dman, GlenH7 Sep 4 '13 at 11:17

This question has been asked before and already has an answer. If those answers do not fully address your question, please ask a new question.

1  
FYI EJBException is unchecked –  Kemoda Sep 3 '13 at 16:05
1  
2  
    
@Kemoda I knew I didn't know. Now I must know why not. –  Niklas rtz Sep 3 '13 at 16:26

1 Answer 1

up vote 6 down vote accepted

Many programs have a top-level global exception handler which catches and logs all unexpected and uncaught exceptions. This means all uncaught unchecked exceptions are logged uniformly.

In this scenario, when faced with a Checked Exception which you cannot deal with or do not expect to ever occur, your easiest way of dealing with it is to simply throw new RuntimeException(ex);, because if you did throw ex; your method would have to declare it (void foo() throws SQLException), and any other methods which called it and didn't catch the exception would also need this declaration.

share|improve this answer

Not the answer you're looking for? Browse other questions tagged or ask your own question.