2

Is it correct to say that the exception mechanism in Java is "chain of responsibility"?

from the one hand, as far as I understand, for every exception that we have in Java, we "run over" the "catch blocks" and check which one is responsible for to handle it, which is look like "chain of responsibility"

but in the other hand, "catch blocks" are not object, and chain of responsibility is talking about "processing objects".

so what am I missing here?

does when I'm writing catch(Exception_class_Name ref){} it means that I'm creating/ implementing some sort of a class? because I couldn't found any suggestion to this thought on web

Matt. Stroh
  • 904
  • 7
  • 16
  • 2
    It is, but it is not an object-oriented chain of responsiblity. – Jazzwave06 Feb 21 '17 at 21:08
  • 1
    IMHO, no. In a chain of responsibility, each link of the chain has a responsibility, and is invoked to handle a fraction of the job. Once a link has done its part of the job (or decides that it has nothing to do), it transfers the responsibility to the next link. In a serie of catch blocks, only one catch block is invoked based on the type of the exception. Related: http://stackoverflow.com/questions/25007427/how-are-exceptions-caught-and-dealt-with-at-the-low-assembly-level – JB Nizet Feb 21 '17 at 21:20

0 Answers0