Ejemplo n.º 1
0
        internal JNetThrowableException(JNetRuntime runtime, jthrowable throwable)
            : base(GetMessage(runtime, throwable))
        {
            // TODO: enrich exception information (asynchronously)

            Throwable = throwable;
        }
Ejemplo n.º 2
0
        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);
        }
Ejemplo n.º 3
0
        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);
        }
Ejemplo n.º 4
0
        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));
        }
Ejemplo n.º 5
0
        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();
            }
        }
Ejemplo n.º 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);
        }