~ubuntu-branches/debian/squeeze/erlang/squeeze

« back to all changes in this revision

Viewing changes to lib/orber/doc/src/ch_exceptions.xml

  • Committer: Bazaar Package Importer
  • Author(s): Sergei Golovan
  • Date: 2009-02-15 16:42:52 UTC
  • mfrom: (1.1.13 upstream)
  • Revision ID: james.westby@ubuntu.com-20090215164252-dxpjjuq108nz4noa
Tags: 1:12.b.5-dfsg-2
Upload to unstable after lenny is released.

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
<?xml version="1.0" encoding="latin1" ?>
 
2
<!DOCTYPE chapter SYSTEM "chapter.dtd">
 
3
 
 
4
<chapter>
 
5
  <header>
 
6
    <copyright>
 
7
      <year>2001</year>
 
8
      <year>2008</year>
 
9
      <holder>Ericsson AB, All Rights Reserved</holder>
 
10
    </copyright>
 
11
    <legalnotice>
 
12
  The contents of this file are subject to the Erlang Public License,
 
13
  Version 1.1, (the "License"); you may not use this file except in
 
14
  compliance with the License. You should have received a copy of the
 
15
  Erlang Public License along with this software. If not, it can be
 
16
  retrieved online at http://www.erlang.org/.
 
17
 
 
18
  Software distributed under the License is distributed on an "AS IS"
 
19
  basis, WITHOUT WARRANTY OF ANY KIND, either express or implied. See
 
20
  the License for the specific language governing rights and limitations
 
21
  under the License.
 
22
 
 
23
  The Initial Developer of the Original Code is Ericsson AB.
 
24
    </legalnotice>
 
25
 
 
26
    <title>CORBA System and User Defined Exceptions</title>
 
27
    <prepared></prepared>
 
28
    <docno></docno>
 
29
    <date>2000-12-19</date>
 
30
    <rev></rev>
 
31
  </header>
 
32
 
 
33
  <section>
 
34
    <title>System Exceptions</title>
 
35
    <p><c>Orber</c>, or any other <c>ORB</c>, may raise a <c>System Exceptions</c>.
 
36
      These exceptions contain status- and minor-fields and may not appear in the
 
37
      operations raises exception IDL-definition.</p>
 
38
 
 
39
    <section>
 
40
      <title>Status Field</title>
 
41
      <p>The status field indicates if the request was completed or not and will be
 
42
        assigned one of the following Erlang atoms:</p>
 
43
      <table>
 
44
        <row>
 
45
          <cell align="center" valign="middle"><em>Status</em></cell>
 
46
          <cell align="center" valign="middle"><em>Description</em></cell>
 
47
        </row>
 
48
        <row>
 
49
          <cell align="left" valign="middle">'COMPLETED_YES'</cell>
 
50
          <cell align="left" valign="middle">The operation was invoked on the target object but an error occurred after the object replied. This occur, for example, if a server replies but Orber is not able to marshal and send the reply to the  client ORB.</cell>
 
51
        </row>
 
52
        <row>
 
53
          <cell align="left" valign="middle">'COMPLETED_NO'</cell>
 
54
          <cell align="left" valign="middle">Orber failed to invoke the operation on the target object. This occur, for example, if the object no longer exists.</cell>
 
55
        </row>
 
56
        <row>
 
57
          <cell align="left" valign="middle">'COMPLETED_MAYBE'</cell>
 
58
          <cell align="left" valign="middle">Orber invoked the operation on the target object but an error occurred and it is impossible to decide if the request really reached the object or not.</cell>
 
59
        </row>
 
60
        <tcaption>Table 1: System Exceptions Status</tcaption>
 
61
      </table>
 
62
    </section>
 
63
 
 
64
    <section>
 
65
      <title>Minor Field</title>
 
66
      <p>The minor field contains an integer (VMCID), which is related to a more
 
67
        specific reason why an invocation failed. The function 
 
68
        <c>orber:exception_info/1</c> can be used to map the minor code to a string. 
 
69
        Note, for VMCID:s not assigned by the OMG or Orber, the documentation
 
70
        for that particular ORB must be consulted.</p>
 
71
    </section>
 
72
 
 
73
    <section>
 
74
      <title>Supported System Exceptions</title>
 
75
      <p>The OMG CORBA specification defines the following exceptions:</p>
 
76
      <list type="bulleted">
 
77
        <item><em>'BAD_CONTEXT'</em> - if a request does not contain a correct
 
78
         context this exception is raised.</item>
 
79
        <item><em>'BAD_INV_ORDER'</em> - this exception indicates that operations
 
80
         has been invoked operations in the wrong order, which would cause,
 
81
         for example, a dead-lock.</item>
 
82
        <item><em>'BAD_OPERATION'</em> - raised if the target object exists, but
 
83
         that the invoked operation is not supported.</item>
 
84
        <item><em>'BAD_PARAM'</em> - is thrown if, for example, a parameter is out
 
85
         of range or otherwise considered illegal.</item>
 
86
        <item><em>'BAD_TYPECODE'</em> - if illegal type code is passed, for example,
 
87
         encapsulated in an any data type the <c>'BAD_TYPECODE'</c> exception
 
88
         will be raised.</item>
 
89
        <item><em>'BAD_QOS'</em> - raised whenever an object cannot support the 
 
90
         required quality of service.</item>
 
91
        <item><em>'CODESET_INCOMPATIBLE'</em> - raised if two ORB's cannot 
 
92
         communicate due to different representation of, for example, 
 
93
        <c>char</c> and/or <c>wchar</c>.</item>
 
94
        <item><em>'COMM_FAILURE'</em> - raised if an ORB is unable to setup 
 
95
         communication or it is lost while an operation is in progress.</item>
 
96
        <item><em>'DATA_CONVERSION'</em> - raised if an ORB cannot convert data 
 
97
         received to the native representation. See also the 
 
98
        <c>'CODESET_INCOMPATIBLE'</c> exception.</item>
 
99
        <item><em>'FREE_MEM'</em> - the ORB failed to free dynamic memory and 
 
100
         failed.</item>
 
101
        <item><em>'IMP_LIMIT'</em> - an implementation limit was exceeded in the
 
102
         ORB at run time. A object factory may, for example, limit the
 
103
         number of object clients are allowed to create.</item>
 
104
        <item><em>'INTERNAL'</em> - an internal failure occurred in an ORB, which
 
105
         is unrecognized. You may consider contacting the ORB providers 
 
106
         support.</item>
 
107
        <item><em>'INTF_REPOS'</em> - the ORB was not able to reach the interface
 
108
         repository, or some other failure relating to the interface 
 
109
         repository is detected.</item>
 
110
        <item><em>'INITIALIZE'</em> - the ORB initialization failed due to, for
 
111
         example, network or configuration error.</item>
 
112
        <item><em>'INVALID_TRANSACTION'</em> - is raised if the request carried an
 
113
         invalid transaction context.</item>
 
114
        <item><em>'INV_FLAG'</em> - an invalid flag was passed to an operation, 
 
115
         which caused, for example, a connection to be closed.</item>
 
116
        <item><em>'INV_IDENT'</em> - this exception indicates that an IDL 
 
117
         identifier is incorrect.</item>
 
118
        <item><em>'INV_OBJREF'</em> - this exception is raised if an objet 
 
119
         reference is malformed or a nil reference (see 
 
120
         also corba:create_nil_objref/0).</item>
 
121
        <item><em>'INV_POLICY'</em> - the invocation cannot be made due to an
 
122
         incompatibility between policy overrides that apply to the
 
123
         particular invocation.</item>
 
124
        <item><em>'MARSHAL'</em> - this exception may be raised by the client- or
 
125
         server-side when either ORB is unable to marshal/unmarshal requests or
 
126
         replies.</item>
 
127
        <item><em>'NO_IMPLEMENT'</em> - if the operation exists but no implementation
 
128
         exists, this exception is raised.</item>
 
129
        <item><em>'NO_MEMORY'</em> - the ORB has run out of memory.</item>
 
130
        <item><em>'NO_PERMISSION'</em> - the caller has insufficient privileges, 
 
131
         such as, for example, bad <c>SSL</c> certificate.</item>
 
132
        <item><em>'NO_RESOURCES'</em> - a general platform resource limit 
 
133
         exceeded.</item>
 
134
        <item><em>'NO_RESPONSE'</em> - no response available of a deferred
 
135
         synchronous request.</item>
 
136
        <item><em>'OBJ_ADAPTER'</em> - indicates administrative mismatch; the object
 
137
         adapter is not able to associate an object with the implementation
 
138
         repository.</item>
 
139
        <item><em>'OBJECT_NOT_EXIST'</em> - the object have been disposed or 
 
140
         terminated; clients should remove all copies of the object reference
 
141
         and initiate desired recovery process.</item>
 
142
        <item><em>'PERSIST_STORE'</em> - the ORB was not able to establish a
 
143
         connection to its persistent storage or data contained in the
 
144
         the storage is corrupted.</item>
 
145
        <item><em>'REBIND'</em> - a request resulted in, for example, a 
 
146
        <c>'LOCATION_FORWARD'</c> message; if the policies are incompatible 
 
147
         this exception is raised.</item>
 
148
        <item><em>'TIMEOUT'</em> - raised if a request fail to complete within the 
 
149
         given time-limit.</item>
 
150
        <item><em>'TRANSACTION_MODE'</em> - a transaction policy mismatch detected.</item>
 
151
        <item><em>'TRANSACTION_REQUIRED'</em> - a transaction is required for the
 
152
         invoked operation but the request contained no transaction context.</item>
 
153
        <item><em>'TRANSACTION_ROLLEDBACK'</em> - the transaction associated with
 
154
         the request has already been rolled back or will be.</item>
 
155
        <item><em>'TRANSACTION_UNAVAILABLE'</em> - no transaction context can be
 
156
         supplied since the ORB is unable to contact the Transaction
 
157
         Service.</item>
 
158
        <item><em>'TRANSIENT'</em> - the ORB could not determine the current status
 
159
         of an object since it could not be reached. The error may be
 
160
         temporary.</item>
 
161
        <item><em>'UNKNOWN'</em> - is thrown if an implementation throws a 
 
162
         non-CORBA, or unrecognized, exception.</item>
 
163
      </list>
 
164
    </section>
 
165
  </section>
 
166
 
 
167
  <section>
 
168
    <title>User Defined Exceptions</title>
 
169
    <p>User exceptions is defined in IDL-files and is listed in operations raises
 
170
      exception listing. For example, if we have the following IDL code:</p>
 
171
    <code type="none">
 
172
module MyModule {
 
173
 
 
174
  exception MyException {};
 
175
  exception MyExceptionMsg { string ExtraInfo; };
 
176
 
 
177
  interface MyInterface {
 
178
 
 
179
    void foo() 
 
180
      raises(MyException);
 
181
 
 
182
    void bar() 
 
183
      raises(MyException, MyExceptionMsg);
 
184
 
 
185
    void baz();
 
186
  };
 
187
};    
 
188
    </code>
 
189
  </section>
 
190
 
 
191
  <section>
 
192
    <title>Throwing Exceptions</title>
 
193
    <p>To be able to raise <c>MyException</c> or <c>MyExceptionMsg</c> exceptions, 
 
194
      the generated <c>MyModule.hrl</c> must be included, and typical usage is:</p>
 
195
    <code type="none">
 
196
-module('MyModule_MyInterface_impl').
 
197
-include("MyModule.hrl").
 
198
 
 
199
bar(State) ->
 
200
    case TestingSomething of
 
201
        ok ->
 
202
           {reply, ok, State};
 
203
        {error, Reason} when list(Reason) ->
 
204
           corba:raise(#'MyModule_MyExceptionMsg'{'ExtraInfo' = Reason});
 
205
        error ->
 
206
           corba:raise(#'MyModule_MyException'{})
 
207
    end.
 
208
    </code>
 
209
  </section>
 
210
 
 
211
  <section>
 
212
    <title>Catching Exceptions</title>
 
213
    <p>Depending on which operation we invoke we must be able to handle:</p>
 
214
    <list type="bulleted">
 
215
      <item>foo - <c>MyException</c> or a system exception.</item>
 
216
      <item>bar - <c>MyException</c>, <c>MyExceptionMsg</c> or a system
 
217
       exception.</item>
 
218
      <item>baz - a system exception.</item>
 
219
    </list>
 
220
    <p>Catching and matching exceptions can bee done in different ways:</p>
 
221
    <code type="none">
 
222
    case catch 'MyModule_MyInterface':bar(MIReference) of
 
223
        ok ->
 
224
           %% The operation raised no exception.
 
225
           ok;
 
226
        {'EXCEPTION', #'MyModule_MyExceptionMsg'{'ExtraInfo' = Reason}} ->
 
227
           %% If we want to log the Reason we must extract 'ExtraInfo'.
 
228
           error_logger:error_msg("Operation 'bar' raised: ~p~n", [Reason]),
 
229
           ... do something ...;
 
230
        {'EXCEPTION', E} when record(E, 'OBJECT_NOT_EXIST') ->
 
231
           ... do something ...;
 
232
        {'EXCEPTION', E} ->
 
233
           ... do something ...
 
234
    end.
 
235
    </code>
 
236
  </section>
 
237
</chapter>
 
238