Presentation is loading. Please wait.

Presentation is loading. Please wait.

Exception Handling in C + + Introduction Overview of C++ Exception Handling Designing With Exceptions Exception Handling Philosophies Conclusion.

Similar presentations


Presentation on theme: "Exception Handling in C + + Introduction Overview of C++ Exception Handling Designing With Exceptions Exception Handling Philosophies Conclusion."— Presentation transcript:

1

2 Exception Handling in C + +

3 Introduction Overview of C++ Exception Handling Designing With Exceptions Exception Handling Philosophies Conclusion

4 Introduction

5 Exception have been around in C++ for a while and are pretty common.

6 Overview

7 trycatchthrow 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.

8 For Example

9 Simple code try { if (! resourceAvail ) throw MyExceptionClass(“Resource Is Not Available”); } catch (MyExceptionClass myException) { //resource was not available, do something cleanup throw; }

10 Designing With Exceptions

11 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.

12 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.

13 Exception HandlingPhilosophies

14 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.

15 Conclusion

16 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.

17 Thank You


Download ppt "Exception Handling in C + + Introduction Overview of C++ Exception Handling Designing With Exceptions Exception Handling Philosophies Conclusion."

Similar presentations


Ads by Google