0

I was told to propagate all exceptions. This sentence means active propagation such like :

public void doSomething() throws SomeException{

try{ doSomethingThatCanThrowException(); } catch (SomeException e){ e.addContextInformation(�more info�); throw e; //throw e, or wrap it � see next line. //throw new WrappingException(e, �more information�); } 

or passive propagation :

public void doSomething() throws SomeException {

try{ doSomethingThatCanThrowException(); } finally { //clean up � close open resources etc. } 

}

.Also what does propagating all exception mean ?

Cheers

3
  • 1
    It means don't catch it, but throw it. Commented Dec 25, 2018 at 12:53
  • So propogating exception mean only to catch it. I should avoid catching it Commented Dec 25, 2018 at 13:02
  • 1
    Catching an exception is a promise: "Whatever caused this exception, my method can fulfill its job even in this exceptional case, so my caller need not be informed about the problem." That's a tough promise, so you better let exceptions propagate to your caller. And if you don't have resources that really need closing, you can go completely without try/catch/finally, just declaring a throws clause for your method. Commented Dec 25, 2018 at 13:33

0

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.