2002-12-18 19:00:25 +03:00
|
|
|
/*
|
2004-04-23 18:21:43 +04:00
|
|
|
Copyright (C) 2002, 2003, 2004 Jeroen Frijters
|
2002-12-18 19:00:25 +03:00
|
|
|
|
|
|
|
This software is provided 'as-is', without any express or implied
|
|
|
|
warranty. In no event will the authors be held liable for any damages
|
|
|
|
arising from the use of this software.
|
|
|
|
|
|
|
|
Permission is granted to anyone to use this software for any purpose,
|
|
|
|
including commercial applications, and to alter it and redistribute it
|
|
|
|
freely, subject to the following restrictions:
|
|
|
|
|
|
|
|
1. The origin of this software must not be misrepresented; you must not
|
|
|
|
claim that you wrote the original software. If you use this software
|
|
|
|
in a product, an acknowledgment in the product documentation would be
|
|
|
|
appreciated but is not required.
|
|
|
|
2. Altered source versions must be plainly marked as such, and must not be
|
|
|
|
misrepresented as being the original software.
|
|
|
|
3. This notice may not be removed or altered from any source distribution.
|
|
|
|
|
|
|
|
Jeroen Frijters
|
|
|
|
jeroen@frijters.net
|
|
|
|
|
|
|
|
*/
|
|
|
|
using System;
|
|
|
|
using System.Reflection;
|
2004-09-09 15:17:55 +04:00
|
|
|
using IKVM.Runtime;
|
|
|
|
using IKVM.Internal;
|
2002-12-18 19:00:25 +03:00
|
|
|
|
2004-08-17 13:05:21 +04:00
|
|
|
abstract class RetargetableJavaException : ApplicationException
|
2002-12-18 19:00:25 +03:00
|
|
|
{
|
2004-08-17 13:05:21 +04:00
|
|
|
internal RetargetableJavaException(string msg) : base(msg)
|
|
|
|
{
|
|
|
|
}
|
2002-12-18 19:00:25 +03:00
|
|
|
|
2004-12-12 17:36:25 +03:00
|
|
|
internal RetargetableJavaException(string msg, Exception x) : base(msg, x)
|
|
|
|
{
|
|
|
|
}
|
|
|
|
|
2004-08-17 13:05:21 +04:00
|
|
|
internal abstract Exception ToJava();
|
|
|
|
}
|
2002-12-18 19:00:25 +03:00
|
|
|
|
2005-08-24 15:35:00 +04:00
|
|
|
// NOTE this is not a Java exception, but instead it wraps a Java exception that
|
|
|
|
// was thrown by a class loader. It is used so ClassFile.LoadClassHelper() can catch
|
|
|
|
// Java exceptions and turn them into UnloadableTypeWrappers without inadvertantly
|
|
|
|
// hiding exceptions caused by coding errors in the IKVM code.
|
|
|
|
class ClassLoadingException : RetargetableJavaException
|
|
|
|
{
|
|
|
|
internal ClassLoadingException(Exception x)
|
|
|
|
: base(x.Message, x)
|
|
|
|
{
|
|
|
|
}
|
|
|
|
|
|
|
|
internal override Exception ToJava()
|
|
|
|
{
|
|
|
|
return InnerException;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2004-08-17 13:05:21 +04:00
|
|
|
class LinkageError : RetargetableJavaException
|
|
|
|
{
|
|
|
|
internal LinkageError(string msg) : base(msg)
|
2002-12-18 19:00:25 +03:00
|
|
|
{
|
|
|
|
}
|
|
|
|
|
2004-12-12 17:36:25 +03:00
|
|
|
internal LinkageError(string msg, Exception x) : base(msg, x)
|
|
|
|
{
|
|
|
|
}
|
|
|
|
|
2004-08-17 13:05:21 +04:00
|
|
|
internal override Exception ToJava()
|
2002-12-18 19:00:25 +03:00
|
|
|
{
|
2004-11-29 16:58:21 +03:00
|
|
|
return JVM.Library.newLinkageError(Message);
|
2002-12-18 19:00:25 +03:00
|
|
|
}
|
2004-08-17 13:05:21 +04:00
|
|
|
}
|
2002-12-18 19:00:25 +03:00
|
|
|
|
2004-08-17 13:05:21 +04:00
|
|
|
class VerifyError : LinkageError
|
|
|
|
{
|
|
|
|
internal VerifyError() : base("")
|
2004-01-28 14:28:16 +03:00
|
|
|
{
|
|
|
|
}
|
|
|
|
|
2004-08-17 13:05:21 +04:00
|
|
|
internal VerifyError(string msg) : base(msg)
|
2002-12-18 19:00:25 +03:00
|
|
|
{
|
|
|
|
}
|
|
|
|
|
2004-12-12 17:36:25 +03:00
|
|
|
internal VerifyError(string msg, Exception x) : base(msg, x)
|
2002-12-18 19:00:25 +03:00
|
|
|
{
|
2004-08-17 13:05:21 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
internal override Exception ToJava()
|
|
|
|
{
|
2004-11-29 16:58:21 +03:00
|
|
|
return JVM.Library.newVerifyError(Message);
|
2004-08-17 13:05:21 +04:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
class ClassNotFoundException : RetargetableJavaException
|
|
|
|
{
|
|
|
|
internal ClassNotFoundException(string name) : base(name)
|
|
|
|
{
|
|
|
|
}
|
|
|
|
|
|
|
|
internal override Exception ToJava()
|
|
|
|
{
|
2004-11-29 16:58:21 +03:00
|
|
|
return JVM.Library.newClassNotFoundException(Message);
|
2004-08-17 13:05:21 +04:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
class ClassCircularityError : LinkageError
|
|
|
|
{
|
|
|
|
internal ClassCircularityError(string msg) : base(msg)
|
|
|
|
{
|
|
|
|
}
|
|
|
|
|
|
|
|
internal override Exception ToJava()
|
|
|
|
{
|
2004-11-29 16:58:21 +03:00
|
|
|
return JVM.Library.newClassCircularityError(Message);
|
2004-08-17 13:05:21 +04:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
class NoClassDefFoundError : LinkageError
|
|
|
|
{
|
|
|
|
internal NoClassDefFoundError(string msg) : base(msg)
|
|
|
|
{
|
|
|
|
}
|
|
|
|
|
|
|
|
internal override Exception ToJava()
|
|
|
|
{
|
2004-11-29 16:58:21 +03:00
|
|
|
return JVM.Library.newNoClassDefFoundError(Message);
|
2004-08-17 13:05:21 +04:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
class IncompatibleClassChangeError : LinkageError
|
|
|
|
{
|
|
|
|
internal IncompatibleClassChangeError(string msg) : base(msg)
|
|
|
|
{
|
|
|
|
}
|
|
|
|
|
|
|
|
internal override Exception ToJava()
|
|
|
|
{
|
2004-11-29 16:58:21 +03:00
|
|
|
return JVM.Library.newIncompatibleClassChangeError(Message);
|
2004-08-17 13:05:21 +04:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
class IllegalAccessError : IncompatibleClassChangeError
|
|
|
|
{
|
|
|
|
internal IllegalAccessError(string msg) : base(msg)
|
|
|
|
{
|
|
|
|
}
|
|
|
|
|
|
|
|
internal override Exception ToJava()
|
|
|
|
{
|
2004-11-29 16:58:21 +03:00
|
|
|
return JVM.Library.newIllegalAccessError(Message);
|
2004-08-17 13:05:21 +04:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
internal class ClassFormatError : LinkageError
|
|
|
|
{
|
|
|
|
internal ClassFormatError(string msg, params object[] p)
|
2005-02-18 14:50:38 +03:00
|
|
|
: base(JavaException.Format(msg, p))
|
2004-08-17 13:05:21 +04:00
|
|
|
{
|
|
|
|
}
|
|
|
|
|
|
|
|
internal override Exception ToJava()
|
|
|
|
{
|
2004-11-29 16:58:21 +03:00
|
|
|
return JVM.Library.newClassFormatError(Message);
|
2004-08-17 13:05:21 +04:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
internal class UnsupportedClassVersionError : ClassFormatError
|
|
|
|
{
|
|
|
|
internal UnsupportedClassVersionError(string msg)
|
|
|
|
: base(msg)
|
|
|
|
{
|
|
|
|
}
|
|
|
|
|
|
|
|
internal override Exception ToJava()
|
|
|
|
{
|
2004-11-29 16:58:21 +03:00
|
|
|
return JVM.Library.newUnsupportedClassVersionError(Message);
|
2004-08-17 13:05:21 +04:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
sealed class JavaException
|
|
|
|
{
|
|
|
|
private JavaException() {}
|
|
|
|
|
2005-02-18 14:50:38 +03:00
|
|
|
internal static string Format(string s, object[] args)
|
|
|
|
{
|
|
|
|
if(args == null || args.Length == 0)
|
|
|
|
{
|
|
|
|
return s;
|
|
|
|
}
|
|
|
|
return String.Format(s, args);
|
|
|
|
}
|
|
|
|
|
2004-08-17 13:05:21 +04:00
|
|
|
internal static Exception IllegalAccessError(string s, params object[] args)
|
|
|
|
{
|
2005-02-18 14:50:38 +03:00
|
|
|
return JVM.Library.newIllegalAccessError(Format(s, args));
|
2004-08-17 13:05:21 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
internal static Exception IllegalAccessException(string s, params object[] args)
|
|
|
|
{
|
2005-02-18 14:50:38 +03:00
|
|
|
return JVM.Library.newIllegalAccessException(Format(s, args));
|
2004-08-17 13:05:21 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
internal static Exception IncompatibleClassChangeError(string s, params object[] args)
|
|
|
|
{
|
2005-02-18 14:50:38 +03:00
|
|
|
return JVM.Library.newIncompatibleClassChangeError(Format(s, args));
|
2002-12-18 19:00:25 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
internal static Exception NoClassDefFoundError(string s, params object[] args)
|
|
|
|
{
|
2005-02-18 14:50:38 +03:00
|
|
|
return JVM.Library.newNoClassDefFoundError(Format(s, args));
|
2002-12-18 19:00:25 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
internal static Exception UnsatisfiedLinkError(string s, params object[] args)
|
|
|
|
{
|
2005-02-23 15:56:15 +03:00
|
|
|
s = Format(s, args);
|
|
|
|
Tracer.Error(Tracer.Jni, "UnsatisfiedLinkError: {0}", s);
|
|
|
|
return JVM.Library.newUnsatisfiedLinkError(s);
|
2002-12-18 19:00:25 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
internal static Exception IllegalArgumentException(string s, params object[] args)
|
|
|
|
{
|
2005-02-18 14:50:38 +03:00
|
|
|
return JVM.Library.newIllegalArgumentException(Format(s, args));
|
2002-12-18 19:00:25 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
internal static Exception NegativeArraySizeException()
|
|
|
|
{
|
2004-11-29 16:58:21 +03:00
|
|
|
return JVM.Library.newNegativeArraySizeException();
|
2002-12-18 19:00:25 +03:00
|
|
|
}
|
|
|
|
|
2004-09-09 15:17:55 +04:00
|
|
|
internal static Exception ArrayStoreException()
|
2003-02-15 14:18:53 +03:00
|
|
|
{
|
2004-11-29 16:58:21 +03:00
|
|
|
return JVM.Library.newArrayStoreException();
|
2003-02-15 14:18:53 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
internal static Exception IndexOutOfBoundsException(string s)
|
|
|
|
{
|
2004-11-29 16:58:21 +03:00
|
|
|
return JVM.Library.newIndexOutOfBoundsException(s);
|
2003-02-15 14:18:53 +03:00
|
|
|
}
|
|
|
|
|
2004-11-29 12:48:01 +03:00
|
|
|
internal static Exception StringIndexOutOfBoundsException()
|
2003-02-15 14:18:53 +03:00
|
|
|
{
|
2004-11-29 16:58:21 +03:00
|
|
|
return JVM.Library.newStringIndexOutOfBoundsException();
|
2003-12-24 14:51:41 +03:00
|
|
|
}
|
2003-02-15 14:18:53 +03:00
|
|
|
|
2002-12-18 19:00:25 +03:00
|
|
|
internal static Exception InvocationTargetException(Exception x)
|
|
|
|
{
|
2004-11-29 16:58:21 +03:00
|
|
|
return JVM.Library.newInvocationTargetException(x);
|
2002-12-18 19:00:25 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
internal static Exception UnknownHostException(string s, params object[] args)
|
|
|
|
{
|
2005-02-18 14:50:38 +03:00
|
|
|
return JVM.Library.newUnknownHostException(Format(s, args));
|
2002-12-18 19:00:25 +03:00
|
|
|
}
|
2003-02-15 12:20:26 +03:00
|
|
|
|
|
|
|
internal static Exception ArrayIndexOutOfBoundsException()
|
|
|
|
{
|
2004-11-29 16:58:21 +03:00
|
|
|
return JVM.Library.newArrayIndexOutOfBoundsException();
|
2003-02-15 12:20:26 +03:00
|
|
|
}
|
2003-02-15 19:18:11 +03:00
|
|
|
|
|
|
|
internal static Exception NumberFormatException(string s, params object[] args)
|
|
|
|
{
|
2005-02-18 14:50:38 +03:00
|
|
|
return JVM.Library.newNumberFormatException(Format(s, args));
|
2003-02-15 19:18:11 +03:00
|
|
|
}
|
2003-02-27 19:41:47 +03:00
|
|
|
|
2003-08-05 18:07:22 +04:00
|
|
|
internal static Exception NullPointerException()
|
|
|
|
{
|
2004-11-29 16:58:21 +03:00
|
|
|
return JVM.Library.newNullPointerException();
|
2003-08-05 18:07:22 +04:00
|
|
|
}
|
2003-08-12 17:09:31 +04:00
|
|
|
|
|
|
|
internal static Exception ClassCastException(string s, params object[] args)
|
|
|
|
{
|
2005-02-18 14:50:38 +03:00
|
|
|
return JVM.Library.newClassCastException(Format(s, args));
|
2003-08-12 17:09:31 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
internal static Exception NoSuchFieldError(string s, params object[] args)
|
|
|
|
{
|
2005-02-18 14:50:38 +03:00
|
|
|
return JVM.Library.newNoSuchFieldError(Format(s, args));
|
2003-08-12 17:09:31 +04:00
|
|
|
}
|
2004-01-11 16:14:42 +03:00
|
|
|
|
2004-08-17 13:05:21 +04:00
|
|
|
internal static Exception NoSuchMethodError(string s, params object[] args)
|
|
|
|
{
|
2005-02-18 14:50:38 +03:00
|
|
|
return JVM.Library.newNoSuchMethodError(Format(s, args));
|
2004-08-17 13:05:21 +04:00
|
|
|
}
|
|
|
|
|
2004-01-11 16:14:42 +03:00
|
|
|
internal static Exception InstantiationError(string s, params object[] args)
|
|
|
|
{
|
2005-02-18 14:50:38 +03:00
|
|
|
return JVM.Library.newInstantiationError(Format(s, args));
|
2004-01-11 16:14:42 +03:00
|
|
|
}
|
2004-08-30 19:56:23 +04:00
|
|
|
|
2004-09-09 15:17:55 +04:00
|
|
|
internal static Exception InstantiationException(string s, params object[] args)
|
|
|
|
{
|
2005-02-18 14:50:38 +03:00
|
|
|
return JVM.Library.newInstantiationException(Format(s, args));
|
2004-09-09 15:17:55 +04:00
|
|
|
}
|
|
|
|
|
2004-08-30 19:56:23 +04:00
|
|
|
internal static Exception InterruptedException()
|
|
|
|
{
|
2004-11-29 16:58:21 +03:00
|
|
|
return JVM.Library.newInterruptedException();
|
2004-08-30 19:56:23 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
internal static Exception IllegalMonitorStateException()
|
|
|
|
{
|
2004-11-29 16:58:21 +03:00
|
|
|
return JVM.Library.newIllegalMonitorStateException();
|
2004-08-30 19:56:23 +04:00
|
|
|
}
|
2002-12-18 19:00:25 +03:00
|
|
|
}
|