How to implement software exception handling
Free C++ Compiler Code Samples C++ Runtime Error: It's a challenge to implement software exception handling for the Intel C++ Compiler that complies with the Microsoft Structured Exception Handling (SHE) implementation. There are, in general, two types of exceptions.

by Rick Winterton, Intel Corp.

Challenge
Implement software exception handling for the Intel® C++ Compiler that is compliant with the Microsoft Structured Exception Handling (SEH) implementation. There are, in general, two types of exceptions.

  1. Asynchronous exceptions: those exceptions that come unexpectedly, similar to an interrupt in a program that takes you immediately away from the thread context you are executing to a context that is different from that which caused the exception.
  2. Synchronous exceptions: those exceptions that are planned and handled in an organized manner. The most common type of synchronous exception is implemented as a "throw."
The following sample code shows synchronous exception handling:



int MyFunction()

int RetVal;
try

throw(ExceptionTypeX);

catch(int MyExpectedType1)

// handle 'int' exception

catch(SomeClassType MyExpectedType2)

// handle class exception

// etc
return RetVal;

The following sample code shows asynchronous exception handling:



try

   Instruction that generates an exception
   return true;

catch(...)
   
   return false;

ISO standard exception handling is a set of entry points provided to the user to handle predefined conditions. These entry points consist of the following:

  • catch -
  • throw -
  • try -
A function defines which exceptions it raises with an exception specification:


throw (MyExceptionType)

The exception type may be one or more type names separated by commas. Handlers within try blocks catch the corresponding exceptions.

Microsoft SEH is a set of Windows functions provided by the operating system. Microsoft Visual C++ abstracts these functions via non-standard keywords and library routines. Other vendors may choose different ways to achieve similar results by calling the same functions. To support SEH, Microsoft extends the C and C++ languages with four keywords:


  • __except -
  • __finally -
  • __leave -
  • __try -

A function defines which exceptions it raises with an exception specification:


throw (MyExceptionTypes)

Subscribers who liked this article also read:
Integrating Java and Microsoft .NET
by Jon Jagger, Content Master Ltd. Intel Corp. The right techniques...
Multithreaded technology and multi-core processors
by Craig Szydlowski, Infrastructure Processor Division, Intel Corp. ...

If you're interested in this topic, these articles may be helpful:

Intel® Threading Building Blocks (TBB)
Intel® Threading Building Blocks (TBB) offers a rich and complete ...
Managing exceptions in Web services environments
from AmberPoint Inc. Web services present us with a standards-base...
DevPartner for Visual C++ BoundsChecker Suite
DevPartner for Visual C++ BoundsChecker Suite is a powerful set of sof...
Intel® TBB for Open Source
Threading Building Blocks (TBB) is an award-winning C++ runtime librar...
Practical C++ Programming, 2nd Edition
by Steve Oualline, O'Reilly Media Inc. C++ is a powerful, highly fl...

Related Jobs:

Software Development Engineer #139806 - WA - Redmond - Microsoft Corporation
Want to be part of the exciting fast-growing Mobile Devices business? ...
Software Development Engineer #137871 - WA - Redmond - Microsoft Corporation
Do you use Internet Explorer every day and find yourself wishing for m...
Programming Writer #142248 - WA - Redmond - Microsoft Corporation
Have you wondered why searching for a workbook is different than searc...
Software Development Engineer in Test #133984 - WA - Redmond - Microsoft Corporation
Imagine being able to find the pictures your friend shared without kno...
Microsoft Engineer - CIN #255356 - OH - Cincinnati - Berbee Information Network Corp
Microsoft Engineer - CIN Oct 4, 2005 Cincinnati,Ohio Send Job ...
Build Management #141602 - WA - Redmond - Microsoft Corporation
Are you an experienced lead looking for the next big opportunity? Wind...
Software Development Engineer in Test #138874 - WA - Redmond - Microsoft Corporation
Do you want to be at the forefront of the next wave of innovation at M...
Network Engineer #101270 - OH - Cincinnati - Berbee Information Network Corp
Network Engineer -CIN May 2, 2005 Cincinnati,Ohio Send Job ...
Network Voice Engineer - CIN #101273 - OH - Cincinnati - Berbee Information Network Corp
Network Voice Engineer - CIN Sep 20, 2005 Cincinnati,Ohio Send...
Software Development Engineer in Test #133116 - WA - Redmond - Microsoft Corporation
Have you ever wondered how your favorite internet site always makes su...