1 / 6

Exceptions

Exceptions. C++ Exceptions are used to propagate unexpected or severe errors. Section of code which may have error is put into try block. Any error which occurs in block is forwarded to exception handler designed by catch clause. Normal flow control is interrupted.

nami
Download Presentation

Exceptions

An Image/Link below is provided (as is) to download presentation Download Policy: Content on the Website is provided to you AS IS for your information and personal use and may not be sold / licensed / shared on other websites without getting consent from its author. Content is provided to you AS IS for your information and personal use only. Download presentation by click this link. While downloading, if for some reason you are not able to download a presentation, the publisher may have deleted the file from their server. During download, if you can't get a presentation, the file might be deleted by the publisher.

E N D

Presentation Transcript


  1. Exceptions

  2. C++ Exceptions are used to propagate unexpected or severe errors. Section of code which may have error is put into try block. Any error which occurs in block is forwarded to exception handler designed by catch clause. Normal flow control is interrupted.

  3. If current function does not catch function, exception propagation continues in the calling function. • Destructors of local objects are executed as objects destroyed. Propagation continues until exception caught or main is exited.

  4. Catch clauses May have multiple catch clauses. • Matching is done in order encountered. • Derived classes will match specifications of base classes. May use (…) as catch clause, which matches any exception.

  5. Throw statement Exception started with throw statement. • May throw an object of any type. • Good design practice to derive exceptions from exception class. • Message passed to constructor. • provides what( ) function which returns message that is passed.

  6. Standard exceptions in <stdexcept> • logic_error • domain_error • invalid_argument • length_error • out_of_range • runtime_error • range_error • overflow_error • underflow_error

More Related