internal JNetThrowableException(JNetRuntime runtime, jthrowable throwable)
            : base(GetMessage(runtime, throwable))
        {
            // TODO: enrich exception information (asynchronously)

            Throwable = throwable;
        }
        public unsafe static string ToString(this JNetRuntime runtime, jstring jstr)
        {
            var jchars = runtime.GetStringChars(jstr, null);
            var str    = ToString(jchars);

            runtime.ReleaseStringChars(jstr, jchars);
            return(str);
        }
        public unsafe static jstring NewString(this JNetRuntime runtime, string str)
        {
            var jchars = AllocJChars(str);
            var result = runtime.NewString(jchars, str.Length);

            Release(jchars);

            return(result);
        }
        private static string GetMessage(JNetRuntime runtime, jthrowable throwable)
        {
            // TODO: Can we get 'throwable' message asynchronously (using another runtime instance)?

            var clz_Throwable = runtime.GetObjectClass(throwable);

            var mid_GetMessage = runtime.GetMethodID(clz_Throwable, "getMessage", "()Ljava/lang/String;");
            var jmessage       = (jstring)runtime.CallObjectMethod(throwable, mid_GetMessage);

            return(runtime.ToString(jmessage));
        }
        public static void ThrowExceptionOccurred(this JNetRuntime runtime)
        {
            if (runtime.ExceptionCheck())
            {
                var ex = runtime.ExceptionOccurred();
                if (ex.HasValue)
                {
                    runtime.ExceptionClear();
                    throw new JNetThrowableException(runtime, ex);
                }

                throw new InvalidOperationException();
            }
        }
Beispiel #6
0
        private static JNetVirtualMachine Boot(IJNetBootstrap bootstrap, JavaVM *vm, JNIEnv *env)
        {
            var instance = new JNetVirtualMachine(vm);

            if (bootstrap is not null)
            {
                var runtime = new JNetRuntime(env);

                try
                {
                    bootstrap.Startup(instance, runtime);
                }
                catch
                {
                    instance.Destroy();
                    throw;
                }
            }

            return(instance);
        }