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

Tonyukuk
  • 5,745
  • 7
  • 35
  • 63
  • 1
    It means don't catch it, but throw it. – ZhaoGang Dec 25 '18 at 12:53
  • So propogating exception mean only to catch it. I should avoid catching it – Tonyukuk Dec 25 '18 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. – Ralf Kleberhoff Dec 25 '18 at 13:33

0 Answers0