|
Description: The Java server throws a Java user exception within a remotely called method which is caught by the .Net client. According to the standard (i.e. OMG's IDL-to-Java mapping) a CORBA user exception defined as OMG IDL is mapped to a Java exception derived from org.omg.CORBA.UserException. Java RMI user exceptions (derived from java.rmi.RemoteException), however, are mapped to an IDL valuetype (according to the OMG Java-to-IDL mapping). To use the standard CORBA exception propagation mechanism these valuetypes have to be wrapped into a (generated) standard IDL exception with a derived name ending with 'Ex', e.g.: MyUserException --> exception MyUserEx (containing a MyUserException) MyUserProblem --> exception MyUserProblemEx (containing a MyUserProblem) MyUserEx --> exception MyUserExEx (containing a MyUserEx) MiddCor extents this mechanism to all Java user exceptions. Being a regular valuetype, though, the user exception requires an implentation on the client side. The mechanism for propagating user exceptions from Java to .Net is essentially transferring an object by value (see also the Objects by value example.) Source: MinCor\DemoJava\Exceptions Mapping: java.lang.Exception <---> Middsol.CORBA.UserException
Example
The Java server:
Interface : Exceptions\Greetings.java
Implementation: Exceptions\GreetingsImpl.java
Exception : Exceptions\MyUserException.java
public class MyUserException extends java.lang.Exception {
public int iId;
public MyUserException( int i)
{
super();
iId = i;
}
public MyUserException()
{
super();
iId = 0;
}
}
The .Net client:
Implementation: ClientImpl.cs
IDL-Files : Exceptions.idl
Exceptions_Ex.idl
Generated : Exceptions.cs
Exception Implementation: MyUserExceptionImpl.cs
public class MyUserExceptionImpl: Exceptions.MyUserException
{
public MyUserExceptionImpl()
{
}
public MyUserExceptionImpl( int a_iValue)
{
this.iId = a_iValue;
}
}
Retrieve the exception (ClientImpl.cs):
try
{
string strRet = oGreetings.hello( "Middsol");
}
catch( Exceptions.MyUserEx ex)
{
Exceptions.MyUserException oMyUserException = (Exceptions.MyUserException)ex.value;
a_oFrmClt.writeLog( "Exception catched: ");
a_oFrmClt.writeLog( " Exceptions.MyUserExceptionID ");
a_oFrmClt.writeLog( " Id:"+ oMyUserException.iId);
a_oFrmClt.writeLog( "");
a_oFrmClt.writeLog( "Stacktrace:");
a_oFrmClt.writeLog( oMyUserException.ToString());
}
Note, that we have to add several items to the list of assemblies to be searched for
by the .Net Reflection. This list is set using the "-AddAssembly" parameter during ORB
initialization:
private static string[] m_strORBInit = {"-ORBEndpoint iiop://localhost:8545/portspan=100",
"-ORBInitRef NameService=corbaloc:iiop:1.2@localhost:1050/NameService",
"-ORBDebug",
"-AddAssembly DotNetClient.exe,JavaBuiltinTypesCF.dll,MinCorCF.dll" };