{[ promptMessage ]}

Bookmark it

{[ promptMessage ]}

13_Review Lecture

If a method declares a checked exception ie an

Info iconThis preview shows page 1. Sign up to view the full content.

View Full Document Right Arrow Icon
This is the end of the preview. Sign up to access the rest of the document.

Unformatted text preview: es are known as unchecked exceptions. All other exceptions are known as checked exceptions, meaning that the compiler forces the programmer to check and deal with the exceptions. ! 6 Catch or Declare Checked Exceptions Java forces you to deal with checked exceptions. If a method declares a checked exception (i.e., an exception other than Error or RuntimeException), you must invoke it in a try-catch block or declare to throw the exception in the calling method. For example, suppose that method p1 invokes method p2 and p2 may throw a checked exception (e.g., IOException), you have to write the code as shown in (a) or (b). 7 Rethrowing Exceptions try { statements; } catch(TheException ex) { perform operations before exits; throw ex; // throw new TheException(); } 8 The finally Clause try { statements; } 1 catch(TheException ex) { . Uncaught excep4on in handling ex; normal flow; 2. Return in error } flow finally { finalStatements; } 9 Catching Exceptions try { statements; // Statements that ma...
View Full Document

{[ snackBarMessage ]}

Ask a homework question - tutors are online