Exception%20Handling - PowerPoint PPT Presentation

About This Presentation
Title:

Exception%20Handling

Description:

... is centered around the three keyword: try, catch, and throw, the general ... try. if (! resourceAvail ) throw MyExceptionClass('Resource Is Not Available' ... – PowerPoint PPT presentation

Number of Views:29
Avg rating:3.0/5.0
Slides: 17
Provided by: walt191
Learn more at: http://www1.chapman.edu
Category:

less

Transcript and Presenter's Notes

Title: Exception%20Handling


1
  • Exception Handling
  • in

C
2
  • Introduction
  • Overview of C Exception Handling
  • Designing With Exceptions
  • Exception Handling Philosophies
  • Conclusion

3
  • Introduction

4
  • Exception have been around in C for a while
    and are pretty common.

5
  • Overview

6
  • C Exception Handling is centered around the
    three keyword try, catch, and throw, the general
    purpose of which is to attempt to execute code
    and handle unexpected exceptional conditions.

7
For Example
8
  • Simple code
  • try
  • if (! resourceAvail )
  • throw MyExceptionClass(Resource Is Not
    Available)
  • catch (MyExceptionClass myException)
  • //resource was not available, do something
    cleanup
  • throw

9
  • Designing With Exceptions

10
  • When implementing the packages which make up
    your applications, such as your core graphics
    engine, it is very useful to define an exceptions
    hierarchy to utilize. This is useful for
    delineating kinds of exceptions as well as
    translating error codes into useful string
    messages.

11
  • A simple base class exception type can contain
    an error message string into which you can place
    your exceptions information. Specifying
    constructors which take parameters that specify
    the file and live number and a string message
    allows for an easy way of storing the origin of
    the exception.
  • You can also put a simple method for logging the
    exceptions which can be called in the constructor
    of a concrete exception class.

12
  • Exception Handling
  • Philosophies

13
Three common reason for throwing an exception
  • 1.  A programming error a pointer is null
    when it should not be
  • 2.  A resource is not available for acquisition
    or release
  • 3. A violation of a class invariant or a state
    of an object invariant -- a calculation that
    goes out of range.

14
  • Conclusion

15
  • Exception Handling is obviously a powerful
    feature of the C language.
  • Exceptions can greatly simplify the development
    of a C package and provide the component writer
    a way to enforce the assumptions made when the
    component was implemented.

16
  • Thank You
Write a Comment
User Comments (0)
About PowerShow.com