{[ promptMessage ]}

Bookmark it

{[ promptMessage ]}

PPT05_Exceptions - Exceptions Exceptions Exceptions are...

Info icon This 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.
Image of page 1

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

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

{[ snackBarMessage ]}

What students are saying

  • Left Quote Icon

    As a current student on this bumpy collegiate pathway, I stumbled upon Course Hero, where I can find study resources for nearly all my courses, get online help from tutors 24/7, and even share my old projects, papers, and lecture notes with other students.

    Student Picture

    Kiran Temple University Fox School of Business ‘17, Course Hero Intern

  • Left Quote Icon

    I cannot even describe how much Course Hero helped me this summer. It’s truly become something I can always rely on and help me. In the end, I was not only able to survive summer classes, but I was able to thrive thanks to Course Hero.

    Student Picture

    Dana University of Pennsylvania ‘17, Course Hero Intern

  • Left Quote Icon

    The ability to access any university’s resources through Course Hero proved invaluable in my case. I was behind on Tulane coursework and actually used UCLA’s materials to help me move forward and get everything together on time.

    Student Picture

    Jill Tulane University ‘16, Course Hero Intern