CORBA IDL exceptions are mapped into standard C# classes, derived from class 'Ics.CORBA.UserException'. Although an exception is conceptionally a valuetype (i.e. passed to the client 'by value'), there is no need to provide a client side implementation, because the MiddCorIdl compiler will generate the complete class code.
IDL exceptions may be declared within the scope of an interface. According to the J-Integra® Espresso IDL-to-C# mapping, this will result in a separate namespace named '<interface>Package' containing the generated class.
(s.f. also the ListArrayStruc example.)
module Excep { interface IGreetings { exception ExcpName { string strWhy; long lErrorCode; }; string hello( in string strName) raises (ExcpName); }; }; |
public class Greetings: GreetingsPOA { public override string hello( string _a_strmyName ) { if( _a_strmyName == "John") { throw new Excep.IGreetingsPackage.ExcpName("John was not friendly", 1001); } System.Console.WriteLine("Function 'Hello' Parameter '{0}'", _a_strmyName); return "Greetings to " + _a_strmyName; } } |
namespace Excep { namespace IGreetingsPackage { public class ExcpName: Ics.CORBA.UserException { public string strWhy; public int lErrorCode; public ExcpName() { } public ExcpName( string strWhy, int lErrorCode ) { this.strWhy = strWhy; this.lErrorCode = lErrorCode; } public ExcpName( string _reason, string strWhy, int lErrorCode ) { this.strWhy = strWhy; this.lErrorCode = lErrorCode; } } } } |
try { // this should work well: System.Console.WriteLine("{0}", m_oIGreetings.hello("Hans")); // this should result in an 'Excep.IGreetingsPackage.ExcpName' exception: System.Console.WriteLine("{0}", m_oIGreetings.hello("John")); } catch( Excep.IGreetingsPackage.ExcpName ex) { System.Console.WriteLine("Exception from Server. Reason:'{0}', ErrorCode:{1}", ex.strWhy, ex.lErrorCode); } |
a.) Start the Server.
b.) Start the Client.