PPT05_Exceptions - Exceptions Exceptions Exceptions are...

Info iconThis preview shows pages 1–2. Sign up to view the full content.

View Full Document Right Arrow Icon
Exceptions Exceptions Exceptions are used as a method for handling errors that the code detects. Keywords try Establishes a block of code in which an exception may occur. catch Establishes a block of code to handle an exception that occurred in the try block. finally Establishes a block of code that is executed regardless of any exceptions. throw The command that throws or sends an exception to the calling method. throws The keyword on a method header that indicates that the method can throw an exception Working with Exceptions Exception Process When a client invokes a method that may create and throw an exception, the invoking code must be placed in a try block The server method indicates it may throw an exception by including the throws keyword in the header If an exception is detected, the server sends an exception instance to the invoking client using the throw keyword The client catches the exception in a catch block The finally block executes regardless of whether an exception is caught Handling Exceptions The correct terminology is to “catch” the exception. Place any statements that may result in an exception in a try block. If your statement invokes a method that throws an exception place the statement in a try block. Create a catch block to handle the exception. Handling Exceptions There is always a catch block associated with a try block. If the try block executes successfully, then it will skip the catch block. If the try block does not execute successfully, then it will directly jump to the catch block skipping any remaining statements in the try block. Handling Exceptions
Background image of page 1

Info iconThis preview has intentionally blurred sections. Sign up to view the full version.

View Full DocumentRight Arrow Icon
Image of page 2
This is the end of the preview. Sign up to access the rest of the document.

This note was uploaded on 10/15/2010 for the course CSIS 345 taught by Professor Dwightstrong during the Spring '10 term at Pittsburg State Uiversity.

Page1 / 5

PPT05_Exceptions - Exceptions Exceptions Exceptions are...

This preview shows document pages 1 - 2. Sign up to view the full document.

View Full Document Right Arrow Icon
Ask a homework question - tutors are online