<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"> <html xmlns:fn="http://www.w3.org/2005/02/xpath-functions"> <head> <meta http-equiv="Content-Type" content="text/html; charset=UTF-8"> <link rel="stylesheet" href="../../../../doc/otp_doc.css" type="text/css"> <title>Erlang -- CORBA System and User Defined Exceptions</title> </head> <body bgcolor="white" text="#000000" link="#0000ff" vlink="#ff00ff" alink="#ff0000"><div id="container"> <script id="js" type="text/javascript" language="JavaScript" src="../../../../doc/js/flipmenu/flipmenu.js"></script><script id="js2" type="text/javascript" src="../../../../doc/js/erlresolvelinks.js"></script><script language="JavaScript" type="text/javascript"> <!-- function getWinHeight() { var myHeight = 0; if( typeof( window.innerHeight ) == 'number' ) { //Non-IE myHeight = window.innerHeight; } else if( document.documentElement && ( document.documentElement.clientWidth || document.documentElement.clientHeight ) ) { //IE 6+ in 'standards compliant mode' myHeight = document.documentElement.clientHeight; } else if( document.body && ( document.body.clientWidth || document.body.clientHeight ) ) { //IE 4 compatible myHeight = document.body.clientHeight; } return myHeight; } function setscrollpos() { var objf=document.getElementById('loadscrollpos'); document.getElementById("leftnav").scrollTop = objf.offsetTop - getWinHeight()/2; } function addEvent(obj, evType, fn){ if (obj.addEventListener){ obj.addEventListener(evType, fn, true); return true; } else if (obj.attachEvent){ var r = obj.attachEvent("on"+evType, fn); return r; } else { return false; } } addEvent(window, 'load', setscrollpos); //--></script><div id="leftnav"><div class="innertube"> <img alt="Erlang logo" src="../../../../doc/erlang-logo.png"><br><small><a href="users_guide.html">User's Guide</a><br><a href="index.html">Reference Manual</a><br><a href="release_notes.html">Release Notes</a><br><a href="../pdf/orber-3.6.24.pdf">PDF</a><br><a href="../../../../doc/index.html">Top</a></small><p><strong>orber</strong><br><strong>User's Guide</strong><br><small>Version 3.6.24</small></p> <br><a href="javascript:openAllFlips()">Expand All</a><br><a href="javascript:closeAllFlips()">Contract All</a><p><small><strong>Chapters</strong></small></p> <ul class="flipMenu" imagepath="../../../../doc/js/flipmenu"> <li id="no" title="The Orber Application" expanded="false">The Orber Application<ul> <li><a href="ch_contents.html"> Top of chapter </a></li> <li title="Content Overview"><a href="ch_contents.html#id61214">Content Overview</a></li> <li title="Brief Description of the User's Guide"><a href="ch_contents.html#id62498">Brief Description of the User's Guide</a></li> </ul> </li> <li id="no" title="Introduction to Orber" expanded="false">Introduction to Orber<ul> <li><a href="ch_introduction.html"> Top of chapter </a></li> <li title="Overview"><a href="ch_introduction.html#id64790">Overview</a></li> </ul> </li> <li id="no" title="The Orber Application" expanded="false">The Orber Application<ul> <li><a href="ch_orber_kernel.html"> Top of chapter </a></li> <li title="ORB Kernel and IIOP "><a href="ch_orber_kernel.html#id57197">ORB Kernel and IIOP </a></li> <li title="The Object Request Broker (ORB)"><a href="ch_orber_kernel.html#id63374">The Object Request Broker (ORB)</a></li> <li title="Internet Inter-Object Protocol (IIOP)"><a href="ch_orber_kernel.html#id65057">Internet Inter-Object Protocol (IIOP)</a></li> </ul> </li> <li id="no" title="Interface Repository" expanded="false">Interface Repository<ul> <li><a href="ch_ifr.html"> Top of chapter </a></li> <li title="Interface Repository(IFR)"><a href="ch_ifr.html#id64309">Interface Repository(IFR)</a></li> </ul> </li> <li id="no" title="Installing Orber" expanded="false">Installing Orber<ul> <li><a href="ch_install.html"> Top of chapter </a></li> <li title="Installation Process "><a href="ch_install.html#id62824">Installation Process </a></li> <li title="Configuration"><a href="ch_install.html#id74009">Configuration</a></li> <li title="Firewall Configuration"><a href="ch_install.html#id76130">Firewall Configuration</a></li> <li title="Interface Configuration"><a href="ch_install.html#id76571">Interface Configuration</a></li> </ul> </li> <li id="no" title="OMG IDL to Erlang Mapping" expanded="false">OMG IDL to Erlang Mapping<ul> <li><a href="ch_idl_to_erlang_mapping.html"> Top of chapter </a></li> <li title="OMG IDL to Erlang Mapping - Overview"><a href="ch_idl_to_erlang_mapping.html#id76788">OMG IDL to Erlang Mapping - Overview</a></li> <li title="OMG IDL Mapping Elements"><a href="ch_idl_to_erlang_mapping.html#id76811">OMG IDL Mapping Elements</a></li> <li title="Getting Started"><a href="ch_idl_to_erlang_mapping.html#id76868">Getting Started</a></li> <li title="Basic OMG IDL Types"><a href="ch_idl_to_erlang_mapping.html#id76929">Basic OMG IDL Types</a></li> <li title="Template OMG IDL Types and Complex Declarators"><a href="ch_idl_to_erlang_mapping.html#id77470">Template OMG IDL Types and Complex Declarators</a></li> <li title="Constructed OMG IDL Types"><a href="ch_idl_to_erlang_mapping.html#id77956">Constructed OMG IDL Types</a></li> <li title="Scoped Names and Generated Files"><a href="ch_idl_to_erlang_mapping.html#id78395">Scoped Names and Generated Files</a></li> <li title="Typecode, Identity and Name Access Functions"><a href="ch_idl_to_erlang_mapping.html#id78787">Typecode, Identity and Name Access Functions</a></li> <li title="References to Constants"><a href="ch_idl_to_erlang_mapping.html#id78931">References to Constants</a></li> <li title="References to Objects Defined in OMG IDL"><a href="ch_idl_to_erlang_mapping.html#id78990">References to Objects Defined in OMG IDL</a></li> <li title="Exceptions"><a href="ch_idl_to_erlang_mapping.html#id79013">Exceptions</a></li> <li title="Access to Attributes"><a href="ch_idl_to_erlang_mapping.html#id79046">Access to Attributes</a></li> <li title="Invocations of Operations"><a href="ch_idl_to_erlang_mapping.html#id79103">Invocations of Operations</a></li> <li title="Implementing the DB Application"><a href="ch_idl_to_erlang_mapping.html#id79262">Implementing the DB Application</a></li> <li title="Reserved Compiler Names and Keywords"><a href="ch_idl_to_erlang_mapping.html#id79480">Reserved Compiler Names and Keywords</a></li> <li title="Type Code Representation"><a href="ch_idl_to_erlang_mapping.html#id80225">Type Code Representation</a></li> </ul> </li> <li id="no" title="CosNaming Service" expanded="false">CosNaming Service<ul> <li><a href="ch_naming_service.html"> Top of chapter </a></li> <li title="Overview of the CosNaming Service"><a href="ch_naming_service.html#id80888">Overview of the CosNaming Service</a></li> <li title="The Basic Use-cases of the Naming Service"><a href="ch_naming_service.html#id81031">The Basic Use-cases of the Naming Service</a></li> <li title="Interoperable Naming Service"><a href="ch_naming_service.html#id81378">Interoperable Naming Service</a></li> </ul> </li> <li id="no" title="How to use security in Orber" expanded="false">How to use security in Orber<ul> <li><a href="ch_security.html"> Top of chapter </a></li> <li title="Security in Orber"><a href="ch_security.html#id82238">Security in Orber</a></li> </ul> </li> <li id="no" title="Orber Stubs/Skeletons" expanded="false">Orber Stubs/Skeletons<ul> <li><a href="ch_stubs.html"> Top of chapter </a></li> <li title="Orber Stubs and Skeletons Description"><a href="ch_stubs.html#id82459">Orber Stubs and Skeletons Description</a></li> </ul> </li> <li id="loadscrollpos" title="CORBA System and User Defined Exceptions" expanded="true">CORBA System and User Defined Exceptions<ul> <li><a href="ch_exceptions.html"> Top of chapter </a></li> <li title="System Exceptions"><a href="ch_exceptions.html#id83036">System Exceptions</a></li> <li title="User Defined Exceptions"><a href="ch_exceptions.html#id83473">User Defined Exceptions</a></li> <li title="Throwing Exceptions"><a href="ch_exceptions.html#id83493">Throwing Exceptions</a></li> <li title="Catching Exceptions"><a href="ch_exceptions.html#id83525">Catching Exceptions</a></li> </ul> </li> <li id="no" title="Orber Interceptors" expanded="false">Orber Interceptors<ul> <li><a href="ch_interceptors.html"> Top of chapter </a></li> <li title="Using Interceptors"><a href="ch_interceptors.html#id83634">Using Interceptors</a></li> <li title="Interceptor Example"><a href="ch_interceptors.html#id83850">Interceptor Example</a></li> </ul> </li> <li id="no" title="OrberWeb" expanded="false">OrberWeb<ul> <li><a href="ch_orberweb.html"> Top of chapter </a></li> <li title="Using OrberWeb"><a href="ch_orberweb.html#id84111">Using OrberWeb</a></li> <li title="Starting OrberWeb"><a href="ch_orberweb.html#id84699">Starting OrberWeb</a></li> </ul> </li> <li id="no" title="Debugging" expanded="false">Debugging<ul> <li><a href="ch_debugging.html"> Top of chapter </a></li> <li title="Tools and FAQ"><a href="ch_debugging.html#id84785">Tools and FAQ</a></li> </ul> </li> </ul> </div></div> <div id="content"> <div class="innertube"> <h1>10 CORBA System and User Defined Exceptions</h1> <h3><a name="id83036">10.1 System Exceptions</a></h3> <p><span class="code">Orber</span>, or any other <span class="code">ORB</span>, may raise a <span class="code">System Exceptions</span>. These exceptions contain status- and minor-fields and may not appear in the operations raises exception IDL-definition.</p> <h4>Status Field</h4> <p>The status field indicates if the request was completed or not and will be assigned one of the following Erlang atoms:</p> <table border="1" cellpadding="2" cellspacing="0"> <tr> <td align="left" valign="middle"><strong>Status</strong></td> <td align="left" valign="middle"><strong>Description</strong></td> </tr> <tr> <td align="left" valign="middle">'COMPLETED_YES'</td> <td 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.</td> </tr> <tr> <td align="left" valign="middle">'COMPLETED_NO'</td> <td align="left" valign="middle">Orber failed to invoke the operation on the target object. This occur, for example, if the object no longer exists.</td> </tr> <tr> <td align="left" valign="middle">'COMPLETED_MAYBE'</td> <td 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.</td> </tr> </table> <em>Table 10.1: System Exceptions Status</em> <h4>Minor Field</h4> <p>The minor field contains an integer (VMCID), which is related to a more specific reason why an invocation failed. The function <span class="code">orber:exception_info/1</span> can be used to map the minor code to a string. Note, for VMCID:s not assigned by the OMG or Orber, the documentation for that particular ORB must be consulted.</p> <h4>Supported System Exceptions</h4> <p>The OMG CORBA specification defines the following exceptions:</p> <ul> <li> <strong>'BAD_CONTEXT'</strong> - if a request does not contain a correct context this exception is raised.</li> <li> <strong>'BAD_INV_ORDER'</strong> - this exception indicates that operations has been invoked operations in the wrong order, which would cause, for example, a dead-lock.</li> <li> <strong>'BAD_OPERATION'</strong> - raised if the target object exists, but that the invoked operation is not supported.</li> <li> <strong>'BAD_PARAM'</strong> - is thrown if, for example, a parameter is out of range or otherwise considered illegal.</li> <li> <strong>'BAD_TYPECODE'</strong> - if illegal type code is passed, for example, encapsulated in an any data type the <span class="code">'BAD_TYPECODE'</span> exception will be raised.</li> <li> <strong>'BAD_QOS'</strong> - raised whenever an object cannot support the required quality of service.</li> <li> <strong>'CODESET_INCOMPATIBLE'</strong> - raised if two ORB's cannot communicate due to different representation of, for example, <span class="code">char</span> and/or <span class="code">wchar</span>.</li> <li> <strong>'COMM_FAILURE'</strong> - raised if an ORB is unable to setup communication or it is lost while an operation is in progress.</li> <li> <strong>'DATA_CONVERSION'</strong> - raised if an ORB cannot convert data received to the native representation. See also the <span class="code">'CODESET_INCOMPATIBLE'</span> exception.</li> <li> <strong>'FREE_MEM'</strong> - the ORB failed to free dynamic memory and failed.</li> <li> <strong>'IMP_LIMIT'</strong> - an implementation limit was exceeded in the ORB at run time. A object factory may, for example, limit the number of object clients are allowed to create.</li> <li> <strong>'INTERNAL'</strong> - an internal failure occurred in an ORB, which is unrecognized. You may consider contacting the ORB providers support.</li> <li> <strong>'INTF_REPOS'</strong> - the ORB was not able to reach the interface repository, or some other failure relating to the interface repository is detected.</li> <li> <strong>'INITIALIZE'</strong> - the ORB initialization failed due to, for example, network or configuration error.</li> <li> <strong>'INVALID_TRANSACTION'</strong> - is raised if the request carried an invalid transaction context.</li> <li> <strong>'INV_FLAG'</strong> - an invalid flag was passed to an operation, which caused, for example, a connection to be closed.</li> <li> <strong>'INV_IDENT'</strong> - this exception indicates that an IDL identifier is incorrect.</li> <li> <strong>'INV_OBJREF'</strong> - this exception is raised if an object reference is malformed or a nil reference (see also corba:create_nil_objref/0).</li> <li> <strong>'INV_POLICY'</strong> - the invocation cannot be made due to an incompatibility between policy overrides that apply to the particular invocation.</li> <li> <strong>'MARSHAL'</strong> - this exception may be raised by the client- or server-side when either ORB is unable to marshal/unmarshal requests or replies.</li> <li> <strong>'NO_IMPLEMENT'</strong> - if the operation exists but no implementation exists, this exception is raised.</li> <li> <strong>'NO_MEMORY'</strong> - the ORB has run out of memory.</li> <li> <strong>'NO_PERMISSION'</strong> - the caller has insufficient privileges, such as, for example, bad <span class="code">SSL</span> certificate.</li> <li> <strong>'NO_RESOURCES'</strong> - a general platform resource limit exceeded.</li> <li> <strong>'NO_RESPONSE'</strong> - no response available of a deferred synchronous request.</li> <li> <strong>'OBJ_ADAPTER'</strong> - indicates administrative mismatch; the object adapter is not able to associate an object with the implementation repository.</li> <li> <strong>'OBJECT_NOT_EXIST'</strong> - the object have been disposed or terminated; clients should remove all copies of the object reference and initiate desired recovery process.</li> <li> <strong>'PERSIST_STORE'</strong> - the ORB was not able to establish a connection to its persistent storage or data contained in the the storage is corrupted.</li> <li> <strong>'REBIND'</strong> - a request resulted in, for example, a <span class="code">'LOCATION_FORWARD'</span> message; if the policies are incompatible this exception is raised.</li> <li> <strong>'TIMEOUT'</strong> - raised if a request fail to complete within the given time-limit.</li> <li> <strong>'TRANSACTION_MODE'</strong> - a transaction policy mismatch detected.</li> <li> <strong>'TRANSACTION_REQUIRED'</strong> - a transaction is required for the invoked operation but the request contained no transaction context.</li> <li> <strong>'TRANSACTION_ROLLEDBACK'</strong> - the transaction associated with the request has already been rolled back or will be.</li> <li> <strong>'TRANSACTION_UNAVAILABLE'</strong> - no transaction context can be supplied since the ORB is unable to contact the Transaction Service.</li> <li> <strong>'TRANSIENT'</strong> - the ORB could not determine the current status of an object since it could not be reached. The error may be temporary.</li> <li> <strong>'UNKNOWN'</strong> - is thrown if an implementation throws a non-CORBA, or unrecognized, exception.</li> </ul> <h3><a name="id83473">10.2 User Defined Exceptions</a></h3> <p>User exceptions is defined in IDL-files and is listed in operations raises exception listing. For example, if we have the following IDL code:</p> <div class="example"><pre> module MyModule { exception MyException {}; exception MyExceptionMsg { string ExtraInfo; }; interface MyInterface { void foo() raises(MyException); void bar() raises(MyException, MyExceptionMsg); void baz(); }; }; </pre></div> <h3><a name="id83493">10.3 Throwing Exceptions</a></h3> <p>To be able to raise <span class="code">MyException</span> or <span class="code">MyExceptionMsg</span> exceptions, the generated <span class="code">MyModule.hrl</span> must be included, and typical usage is:</p> <div class="example"><pre> -module('MyModule_MyInterface_impl'). -include("MyModule.hrl"). bar(State) -> case TestingSomething of ok -> {reply, ok, State}; {error, Reason} when list(Reason) -> corba:raise(#'MyModule_MyExceptionMsg'{'ExtraInfo' = Reason}); error -> corba:raise(#'MyModule_MyException'{}) end. </pre></div> <h3><a name="id83525">10.4 Catching Exceptions</a></h3> <p>Depending on which operation we invoke we must be able to handle:</p> <ul> <li>foo - <span class="code">MyException</span> or a system exception.</li> <li>bar - <span class="code">MyException</span>, <span class="code">MyExceptionMsg</span> or a system exception.</li> <li>baz - a system exception.</li> </ul> <p>Catching and matching exceptions can bee done in different ways:</p> <div class="example"><pre> case catch 'MyModule_MyInterface':bar(MIReference) of ok -> %% The operation raised no exception. ok; {'EXCEPTION', #'MyModule_MyExceptionMsg'{'ExtraInfo' = Reason}} -> %% If we want to log the Reason we must extract 'ExtraInfo'. error_logger:error_msg("Operation 'bar' raised: ~p~n", [Reason]), ... do something ...; {'EXCEPTION', E} when record(E, 'OBJECT_NOT_EXIST') -> ... do something ...; {'EXCEPTION', E} -> ... do something ... end. </pre></div> </div> <div class="footer"> <hr> <p>Copyright © 1997-2012 Ericsson AB. All Rights Reserved.</p> </div> </div> </div></body> </html>