Salome HOME
This commit was generated by cvs2git to create tag 'V1_4_0b2'.
[modules/kernel.git] / doc / KernelResources / kernel_resources-2.html
1 <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 3.2 Final//EN">
2 <HTML>
3 <HEAD>
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>
9 </HEAD>
10 <BODY>
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>
14 <HR>
15 <H2><A NAME="s2">2. Exceptions</A></H2>
16
17 <H2><A NAME="ss2.1">2.1 C++ exceptions: class SALOME_Exception</A>
18 </H2>
19
20 <H3>definition</H3>
21
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
29 class exception.
30 <H3>usage</H3>
31
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>&quot;<CODE>utils_SALOME_Exception.hxx</CODE>&quot;
35 <P>The <CODE>SALOME_Exception</CODE> constructor is:
36 <P>
37 <PRE>
38 SALOME_Exception( const char *text,
39                   const char *fileName=0, 
40                   const unsigned int lineNumber=0 );
41 </PRE>
42 <P>The exception is raised like this:
43 <P>
44 <PRE>
45 throw SALOME_Exception(&quot;my pertinent message&quot;);
46 </PRE>
47 <P>or like this:
48 <P>
49 <PRE>
50 throw SALOME_Exception(LOCALIZED(&quot;my pertinent message&quot;));
51 </PRE>
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:
55 <P>
56 <PRE>
57 try
58   {
59     ...
60   }
61 catch (const SALOME_Exception &amp;ex)
62   {
63     cerr &lt;&lt; ex.what() &lt;&lt;endl;
64   }
65 </PRE>
66 <P>The <CODE>what()</CODE> method overrides the one defined in the STL exception
67 class.
68 <H2><A NAME="ss2.2">2.2 CORBA exceptions</A>
69 </H2>
70
71 <H3>definition</H3>
72
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
79 a single catch.
80 <P>The exception types defined in idl are:
81 <P>
82 <DL>
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).
86 </DL>
87 <P>CORBA system and user exceptions already defined in the packages
88 used within SALOME, such as OmniORB exceptions, must be handled separately.
89 <H3>usage</H3>
90
91 <H3>CORBA servant, C++</H3>
92
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>:
95 <P>
96 <PRE>
97 #include &quot;Utils_CorbaException.hxx&quot;
98 </PRE>
99 <P>The exception is raised with a macro which appends file name
100 and line number.
101 <P>
102 <PRE>
103 if (myStudyName.size() == 0)
104    THROW_SALOME_CORBA_EXCEPTION(&quot;No Study Name given&quot;, \
105                                 SALOME::BAD_PARAM);
106 </PRE>
107 <H3>CORBA Client, GUI Qt C++</H3>
108
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>:
111 <P>
112 <PRE>
113 #include &quot;SALOMEGUI_QtCatchCorbaException.hxx&quot;
114 </PRE>
115 <P>A typical exchange with a CORBA Servant will be:
116 <P>
117 <PRE>
118 try
119   {
120     ... // one ore more CORBA calls
121   }
122 catch (const SALOME::SALOME_Exception &amp; S_ex)
123   {
124     QtCatchCorbaException(S_ex);
125   }
126 </PRE>
127 <H3>CORBA Client, C++, without GUI</H3>
128
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.
132 <HR>
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>
136 </BODY>
137 </HTML>