.netikvm

How to cast .NET exception to Java Exception using IKVM?


My solutions design is as folows

+--------------------+
|     .NET exe       |     throws .NET Exception 
|--------------------|
|      IKVM          |             |  <------------auto conversion?
+--------------------+             v
|  java jar assembly |       java exception 
+--------------------+

When .net exe throw an exception, such as System.NotSupportedException into java jar library assembly, java-based assembly expects java exception are thrown while .net library exception is based upon non-java exception.

It works fine if .NET try{}catch{} converts .net exception into ikvm java exception.

But i don't think it is smart way.

Is there any way to convert .NET exceptions to java exceptions gracefully?


Solution

  • I would not throw the .NET exception to the Java layer any more than I would allow an exception to cross the boundary from my HTTP layer to a client view.

    I think the .NET component ought to catch and handle all exceptions and communicate the failure to Java in a manner that's better for the client.