From: William S F. <ws...@fu...> - 2013-11-11 18:47:41
|
On 22/10/13 15:16, Marvin Greenberg wrote: > I'm looking at migrating the director exception handling from Java over > to C#. I actually think there is more work than a simple port -- the C# > capabilities are missing some of the preexisting (before my patch) > capabilities in Java. Specifically, the equivalent of a "throws" > typemap in java to map thrown exceptions from C++ into an "equivalent" > exception in C#. The throws typemap should work in C#. What isn't working? Perhaps you are referring to the 'throws' attribute in all the Java typemaps? These are very Java specific for checked exceptions and not relevant to C# though. But, for now I have a simple question as I'm trying to > understand the process of carrying exceptions from the C++ layer into C#. > > In the code below, is numExceptionsPending serving any purpose? It > seems like only a single exception can be pending. Is this some > performance issue -- assignments are expensive so don't want to hold the > lock? It seems like simply testing pendingException for null is > sufficient. It is a performance optimisation where performance is most critical when there are no exceptions pending and hence a non-thread local variable is read in the normal code path which is a lot faster than reading a thread local variable. There is the possibility of more than one exception pending if more than one thread is in use. The csharp_exceptions_runme.cs file tests this. With regard to the Java exceptions patch, I think there are a handful more things to be done, that is: - Derive DirectorException from std::exception in all languages for consistency as well as add in support for directorthrows in the other director languages for a consistent experience for directors and exceptions. - Add support for $packagepath/$javaclassname in the Java "throws" typemap using a call to canonicalizeJNIDescriptor() - Your patches to directorout typemaps and std_string.i add in an if (!jenv->ExceptionCheck()) call. This needs to be done in all Java directorout typemaps that throw exceptions and also in the documentation (and examples/test-suite) - Have you looked at the two warnings in the Java test-suite, they look related to director exceptions: WARNING in native method: JNI call made with exception pending at director_abstract.director_abstractJNI.Foo_ping(Native Method) at director_abstract.Foo.ping(Foo.java:54) at director_abstract_runme.main(director_abstract_runme.java:29) WARNING in native method: JNI call made with exception pending at director_exception.director_exceptionJNI.Foo_pongSwigExplicitFoo__SWIG_1(Native Method) at director_exception.Foo.pong(Foo.java:62) at director_exception_runme.main(director_exception_runme.java:21) William |