exercisesApril908

exercisesApril908 - • a catch can only have a single...

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

View Full Document Right Arrow Icon
COMP202 Instructor: Ladan Mahabadi April 9, 2008 Throwing exceptions A method will throw an exception when the method that detects an error is unable to deal with it. There is no guarantee that an error will be handled but utilizing throws will enable you as a programmer to separate the portion of a program that handles exceptions from the portion that generates it. A throw statement specifies an (exception) object to be thrown. This object needs to be derived from class Throwable (which includes classes Exception and Error as subclasses). Error s: serious system problems that generally should not be caught Exception s: problems that are caused by programs; (should) deal with these Exception Handlers: contained in catch blocks in the catch brackets you need to indicate the type of exception that’s being caught here and a parameter name
Image of page 1

Info iconThis 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.

Unformatted text preview: • a catch can only have a single argument (can’t use comma seperated arguments) • You can not handle the same type of error in two different catch blocks associated with a particular try block • Placing catch( Exception e ) before other catch blocks prevents other (specific) types of exceptions from being executed; catch( Exception e ) should always be placed last in the list of exception handlers following a try block Rethrowing an Exception A catch handler that catches an exception may determine that it can not handle that error well and it may allow another catch handler to deal with the problem. In these cases, the handler can rethrow the exception to the next enclosing try block by (even if it has processed it a bit) : throw e;...
View Full 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