コード例 #1
0
        private T SafeJniCall <T>(Func <T> func)
        {
            _env.GetDelegate <ExceptionClear>()(_currentThreadEnv.Value);
            T ret = func();

            if (_env.GetDelegate <ExceptionCheck>()(_currentThreadEnv.Value))
            {
                IntPtr exception = _env.GetDelegate <ExceptionOccurred>()(_currentThreadEnv.Value);
                _env.GetDelegate <ExceptionClear>()(_currentThreadEnv.Value);
                string          exceptionType    = GetExceptionType(exception);
                JThrowableClass throwableClass   = new JThrowableClass(this);
                string          exceptionMessage = throwableClass.GetMessage(exception);
                exceptionMessage = AppendCause(exceptionMessage, exception, throwableClass);
                throw new JavaException(exceptionType + (String.IsNullOrEmpty(exceptionMessage) ? "" : ": " + exceptionMessage),
                                        javaStackTrace: throwableClass.GetStackTrace(exception));
            }
            return(ret);
        }
コード例 #2
0
        private string AppendCause(string exceptionMessage, IntPtr exception, JThrowableClass throwableClass)
        {
            IntPtr cause = throwableClass.GetCause(exception);

            if (cause == IntPtr.Zero)
            {
                return(exceptionMessage);
            }
            else
            {
                string causeType    = GetExceptionType(cause);
                string causeMessage = throwableClass.GetMessage(exception);
                if (causeMessage != null)
                {
                    exceptionMessage = (exceptionMessage ?? "") + ". Caused by: " + causeType + ": " + causeMessage;
                }
                return(AppendCause(exceptionMessage, cause, throwableClass));
            }
        }