10.11.2014 Views

Exception Handling in Java

Exception Handling in Java

Exception Handling in Java

SHOW MORE
SHOW LESS

Create successful ePaper yourself

Turn your PDF publications into a flip-book with our unique Google optimized e-Paper software.

The try and catch Statement<br />

To process an exception when it occurs, the l<strong>in</strong>e that throws the exception is<br />

executed with<strong>in</strong> a try block<br />

A try block is followed by one or more catch clauses, which conta<strong>in</strong> code to process<br />

an exception<br />

Each catch clause has an associated exception type. When an exception occurs,<br />

process<strong>in</strong>g cont<strong>in</strong>ues at the first catch clause that matches the exception type<br />

try {<br />

// Code that might generate exceptions<br />

} catch(Type1 id1) {<br />

// Handle exceptions of Type1<br />

} catch(Type2 id2) {<br />

// Handle exceptions of Type2<br />

} catch(Type3 id3) {<br />

// Handle exceptions of Type3<br />

}<br />

// etc...<br />

4

Hooray! Your file is uploaded and ready to be published.

Saved successfully!

Ooh no, something went wrong!