1
<?xml version="1.0" encoding="latin1" ?>
2
<!DOCTYPE chapter SYSTEM "chapter.dtd">
9
<holder>Ericsson AB, All Rights Reserved</holder>
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/.
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
23
The Initial Developer of the Original Code is Ericsson AB.
26
<title>CORBA System and User Defined Exceptions</title>
29
<date>2000-12-19</date>
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>
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>
45
<cell align="center" valign="middle"><em>Status</em></cell>
46
<cell align="center" valign="middle"><em>Description</em></cell>
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>
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>
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>
60
<tcaption>Table 1: System Exceptions Status</tcaption>
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>
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
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
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
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
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
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
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
161
<item><em>'UNKNOWN'</em> - is thrown if an implementation throws a
162
non-CORBA, or unrecognized, exception.</item>
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>
174
exception MyException {};
175
exception MyExceptionMsg { string ExtraInfo; };
177
interface MyInterface {
183
raises(MyException, MyExceptionMsg);
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>
196
-module('MyModule_MyInterface_impl').
197
-include("MyModule.hrl").
200
case TestingSomething of
203
{error, Reason} when list(Reason) ->
204
corba:raise(#'MyModule_MyExceptionMsg'{'ExtraInfo' = Reason});
206
corba:raise(#'MyModule_MyException'{})
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
218
<item>baz - a system exception.</item>
220
<p>Catching and matching exceptions can bee done in different ways:</p>
222
case catch 'MyModule_MyInterface':bar(MIReference) of
224
%% The operation raised no exception.
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 ...;