The class SALOME_Exception
provides a generic method to send
a message, with optional source file name and line number. This class
is intended to serve as a base class for all kinds of exceptions
SALOME code. All the exceptions derived from SALOME_Exception
could
be handled in a single catch, in which the message associated to
the exception is displayed, or sent to a log file.
The class SALOME_Exception
inherits its behavior from the STL
class exception.
The header SALOME/src/utils/utils_SALOME_Exception.hxx
must be
included in the C++ source, when raised or trapped:
#include
"utils_SALOME_Exception.hxx
"
The SALOME_Exception
constructor is:
SALOME_Exception( const char *text, const char *fileName=0, const unsigned int lineNumber=0 );
The exception is raised like this:
throw SALOME_Exception("my pertinent message");
or like this:
throw SALOME_Exception(LOCALIZED("my pertinent message"));
where LOCALIZED is a macro provided with utils_SALOME_Exception.hxx
which gives file name and line number.
The exception is handled like this:
try { ... } catch (const SALOME_Exception &ex) { cerr << ex.what() <<endl; }
The what()
method overrides the one defined in the STL exception
class.
The idl SALOME_Exception
provides a generic CORBA exception for
SALOME, with an attribute that gives an exception type,a message,
plus optional source file name and line number.
This idl is intended to serve for all user CORBA exceptions raised in SALOME code, as IDL specification does not support exception inheritance. So, all the user CORBA exceptions from SALOME could be handled in a single catch.
The exception types defined in idl are:
CORBA communication problem,
Bad User parameters,
application level problem (often irrecoverable).
CORBA system and user exceptions already defined in the packages used within SALOME, such as OmniORB exceptions, must be handled separately.
The CORBA Server header for SALOME_Exception
and a macro to throw
the exception are provided with the header SALOME/src/Utils/Utils_CorbaException.hxx
:
#include "Utils_CorbaException.hxx"
The exception is raised with a macro which appends file name and line number.
if (myStudyName.size() == 0) THROW_SALOME_CORBA_EXCEPTION("No Study Name given", \ SALOME::BAD_PARAM);
The CORBA Client header for SALOME_Exception
and a Qt function
header that displays a message box are provided in SALOME/src/SALOMEGUI/SALOMEGUI_QtCatchCorbaException.hxx
:
#include "SALOMEGUI_QtCatchCorbaException.hxx"
A typical exchange with a CORBA Servant will be:
try { ... // one ore more CORBA calls } catch (const SALOME::SALOME_Exception & S_ex) { QtCatchCorbaException(S_ex); }
Nothing specific has been provided to the developer yet. See
the idl or the Qt function SALOMEGUI_QtCatchCorbaException.hxx
to
see how to get the information given by the exception object.