Hide menu
Loading...
Searching...
No Matches
cadex::Base_SEHOwner Class Reference

Oversees signals and exception handling. More...

#include <cadex/Base_SEHOwner.hxx>

Public Member Functions

 Base_SEHOwner (bool theFPE=false)
 Constructor.
 
 ~Base_SEHOwner ()
 Destructor.
 

Detailed Description

Oversees signals and exception handling.

Base_SEHOwner sets up handlers for selected structured exceptions (on Windows) and signals (on Linux). Upon exiting its scope the object restores previous handlers.

The handlers are called by the operating system for the signal and convert it into respective C++ exception that can be internally called by CAD Exchanger. In this role, Base_SEHOwner can be used to protect against internal errors that may exist in CAD Exchanger or third-party libraries, such as access by invalid pointer or division by zero.

The typical usage of Base_SEHOwner is as follows:

{
Base_SEHOwner aSEHOwner;
//call to CAD Exchanger API
}
Oversees signals and exception handling.
Definition: Base_SEHOwner.hxx:30

Similar approach can be used to protect a call to user own code without any use of CAD Exchanger:

{
Base_SEHOwner aSEHOwner;
//...
try {
//call to user's code
} catch (const std::exception& e) {
//...
} catch (...) {
//...
}
}

Base_SEHOwner is intentionally made a public class which the user may decide to or not to create even for exclusive CAD Exchanger usage. CAD Exchanger does not internally create objects of Base_SEHOwner to not override exception and signal handlers that might have been set by the user.

Base_SEHOwner activates per-process and per-thread handlers. Base_SEHOwner propagates per-thread handlers accross own CAD Exchanger worker threads. For the user created threads, it is a user responsibility to create an instance of Base_SEHOwner in each thread to properly set up handlers.

Base_SEHOwner can also set up floating point (FP) handlers which will be activated when some abnormal situation with FP numbers is encountered (e.g. division by zero, overflow, etc). By default FP handlers are not activated and computations can continue (e.g. infinity will be created when dividing by zero).

Currently Base_SEHOwner protects against only a few exceptions/signals that can appear during execution, it does not provide handling of all signals (e.g. SIGTERM, etc). On Windows the list of processed exception is described at http://msdn.microsoft.com/en-us/library/windows/desktop/aa363082%28v=vs.85%29.aspx (where FP cases are only processed if the FP handling has been enabled in the constructor).

Constructor & Destructor Documentation

◆ Base_SEHOwner()

cadex::Base_SEHOwner::Base_SEHOwner ( bool  theFPE = false)

Constructor.

theFPE specifies whether FP exception handling should be enabled. For CAD Exchanger algorithms it is not recommended to set it to true. Otherwise some interim data which can be safely processed by CAD Exchanger can cause a premature exception leading to larger data loss.

When protecting own user code this parameter should be set at user's discretion.

◆ ~Base_SEHOwner()

cadex::Base_SEHOwner::~Base_SEHOwner ( )

Destructor.

Restores handlers existed at the moment of creation of this object.