Visual C++ .NET is smiling to you, please return her smile

The Visual C++ Programming Tutorials: C++ Exception Handling







Exceptions are an error-handling mechanism employed extensively in C++ and several other modern programming languages. It is one of the important topics in any programming because properly implemented exception handling can increase the 'product quality'. Exceptions provide an alternative error-handling mechanism, which gives you three main advantages over traditional return value error  handling:

  1. Exceptions can’t be ignored. If an exception isn’t handled at some point, the program will terminate, which makes exceptions suitable for handling critical errors.

  2. Exceptions don’t have to be handled at the point where the exception occurs. An error can occur at many levels of a function calls deep in a program, and there might not be a way to fix the problem at the point where the error occurs. Exceptions let you handle the error anywhere up the call stack.

  3. Exceptions provide a useful way to signal errors where a return value can’t be used. There are two particular places in C++ where return values can’t be used: constructors don’t use them, and overloaded operators can’t have their return value overloaded to use for error and status information. Exceptions are particularly useful in these situations because they let you sidestep the normal return-value mechanism.

The handler for an exception can occur in the routine in which the exception was thrown. It can also occur in any routine above it in the call stack, and, at run time, each routine in the call stack is checked to see if it implements a suitable handler. If nothing suitable has been found by the time the top of the stack has been reached, the program terminates.

In .NET, they can be used across languages. Because exceptions are part of the underlying .NET Framework, it’s possible to throw an exception in C++ code and catch it in Microsoft Visual Basic .NET, something that isn’t possible outside the .NET environment. So, you will find the DLL program example in this Tutorial created in VC++ .NET and then used by Visual Basic .NET. The following list is the topics in this Chapter.

  1. C++ Exception Handling 1: What Are Exceptions?, The Call Stack and Exceptions, How Do Exceptions Work?, Exception Types, Throwing Exceptions and What Can You Throw?

  2. C++ Exception Handling 2: Handling Exceptions, Using the try-catch Construct, Customizing Exception Handling, Using the Exception Hierarchy and Using Exceptions with Constructors

  3. C++ Exception Handling 3: Nesting and Re-throwing Exceptions, The finally Block



  5. C++ Exception Handling 4: The catch (...) Block, Creating Your Own Exception Types and Using value Classes

  6. C++ Exception Handling 5: Using __try_cast (old syntax, Managed Extension for C++) for Dynamic Casting - safe_cast for Dynamic Casting (new syntax), Upcast with safe_cast and Downcast with safe_cast

  7. C++ Exception Handling 6: safe_cast and Generic Types, safe_cast and User-Defined Conversions (UDC), safe_cast and Boxing, safe_cast and Unboxing

  8. C++ Exception Handling 7: Using Exceptions Across Languages and Quick Reference




Best viewed using FireFox, Chrome etc. Worst viewed using IE of any version


Webmaster contact: [contact[@]]

Copyright 2019 © Visualcplusdotnet. All rights reserved.

Excellent hosting services provided by MochaHost - The Online Central



| About | Disclaimer | Privacy | Site Index & Project Download | Native C | Contact |



Custom Search