Answer:
Yes.
How try and catch Work
Here is how try and catch work:
- When an
Exceptionis thrown by a statement in thetry{}block, thecatch{}blocks are examined one-by-one starting starting with the first. - The first
catch{}block to match the type of theExceptiongets control. - Only one
catch{}block gets control. - If no
catch{}block matches theException, none is picked, and execution leaves this method (just as if there were notry{}block.) - The most specific
Exceptiontypes should appear first in the structure, followed by the more generalExceptiontypes. - The statements in the chosen
catch{}block execute sequentially. After the last statement executes, control goes to the first statement that follows thetry/catchstructure. - Control does not return to the
tryblock.
QUESTION 7:
Must the catch{} blocks list all possible Exceptions?