1 <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 3.2 Final//EN">
4 <META NAME="GENERATOR" CONTENT="SGML-Tools 1.0.9">
5 <TITLE>SALOME Kernel resources for developer: Exceptions</TITLE>
6 <LINK HREF="kernel_resources-3.html" REL=next>
7 <LINK HREF="kernel_resources-1.html" REL=previous>
8 <LINK HREF="kernel_resources.html#toc2" REL=contents>
11 <A HREF="kernel_resources-3.html">Next</A>
12 <A HREF="kernel_resources-1.html">Previous</A>
13 <A HREF="kernel_resources.html#toc2">Contents</A>
15 <H2><A NAME="s2">2. Exceptions</A></H2>
17 <H2><A NAME="ss2.1">2.1 C++ exceptions: class SALOME_Exception</A>
22 <P>The class <CODE>SALOME_Exception</CODE> provides a generic method to send
23 a message, with optional source file name and line number. This class
24 is intended to serve as a base class for all kinds of exceptions
25 SALOME code. All the exceptions derived from <CODE>SALOME_Exception</CODE> could
26 be handled in a single catch, in which the message associated to
27 the exception is displayed, or sent to a log file.
28 <P>The class <CODE>SALOME_Exception</CODE> inherits its behavior from the STL
32 <P>The header <CODE>SALOME/src/utils/utils_SALOME_Exception.hxx</CODE> must be
33 included in the C++ source, when raised or trapped:
34 <P><CODE>#include </CODE>"<CODE>utils_SALOME_Exception.hxx</CODE>"
35 <P>The <CODE>SALOME_Exception</CODE> constructor is:
38 SALOME_Exception( const char *text,
39 const char *fileName=0,
40 const unsigned int lineNumber=0 );
42 <P>The exception is raised like this:
45 throw SALOME_Exception("my pertinent message");
50 throw SALOME_Exception(LOCALIZED("my pertinent message"));
52 <P>where LOCALIZED is a macro provided with <CODE>utils_SALOME_Exception.hxx</CODE>
53 which gives file name and line number.
54 <P>The exception is handled like this:
61 catch (const SALOME_Exception &ex)
63 cerr << ex.what() <<endl;
66 <P>The <CODE>what()</CODE> method overrides the one defined in the STL exception
68 <H2><A NAME="ss2.2">2.2 CORBA exceptions</A>
73 <P>The idl <CODE>SALOME_Exception</CODE> provides a generic CORBA exception for
74 SALOME, with an attribute that gives an exception type,a message,
75 plus optional source file name and line number.
76 <P>This idl is intended to serve for all user CORBA exceptions raised
77 in SALOME code, as IDL specification does not support exception inheritance.
78 So, all the user CORBA exceptions from SALOME could be handled in
80 <P>The exception types defined in idl are:
83 <DT><B>COMM</B><DD><P>CORBA communication problem,
84 <DT><B>BAD_PARAM</B><DD><P>Bad User parameters,
85 <DT><B>INTERNAL_ERROR</B><DD><P>application level problem (often irrecoverable).
87 <P>CORBA system and user exceptions already defined in the packages
88 used within SALOME, such as OmniORB exceptions, must be handled separately.
91 <H3>CORBA servant, C++</H3>
93 <P>The CORBA Server header for <CODE>SALOME_Exception</CODE> and a macro to throw
94 the exception are provided with the header <CODE>SALOME/src/Utils/Utils_CorbaException.hxx</CODE>:
97 #include "Utils_CorbaException.hxx"
99 <P>The exception is raised with a macro which appends file name
103 if (myStudyName.size() == 0)
104 THROW_SALOME_CORBA_EXCEPTION("No Study Name given", \
107 <H3>CORBA Client, GUI Qt C++</H3>
109 <P>The CORBA Client header for <CODE>SALOME_Exception</CODE> and a Qt function
110 header that displays a message box are provided in <CODE>SALOME/src/SALOMEGUI/SALOMEGUI_QtCatchCorbaException.hxx</CODE>:
113 #include "SALOMEGUI_QtCatchCorbaException.hxx"
115 <P>A typical exchange with a CORBA Servant will be:
120 ... // one ore more CORBA calls
122 catch (const SALOME::SALOME_Exception & S_ex)
124 QtCatchCorbaException(S_ex);
127 <H3>CORBA Client, C++, without GUI</H3>
129 <P>Nothing specific has been provided to the developer yet. See
130 the idl or the Qt function <CODE>SALOMEGUI_QtCatchCorbaException.hxx</CODE> to
131 see how to get the information given by the exception object.
133 <A HREF="kernel_resources-3.html">Next</A>
134 <A HREF="kernel_resources-1.html">Previous</A>
135 <A HREF="kernel_resources.html#toc2">Contents</A>