ikvm-fork/runtime/JavaException.cs

215 строки
4.5 KiB
C#
Исходник Обычный вид История

2002-12-18 19:00:25 +03:00
/*
Copyright (C) 2002, 2003, 2004, 2005, 2006, 2007 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.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)
{
}
internal static string Format(string s, object[] args)
{
if (args == null || args.Length == 0)
{
return s;
}
return String.Format(s, args);
}
#if !STATIC_COMPILER && !FIRST_PASS
2004-08-17 13:05:21 +04:00
internal abstract Exception ToJava();
#elif FIRST_PASS
internal virtual Exception ToJava()
{
return null;
}
2006-04-10 13:09:09 +04:00
#endif
2004-08-17 13:05:21 +04:00
}
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)
{
}
2006-04-10 13:09:09 +04:00
#if !STATIC_COMPILER
2005-08-24 15:35:00 +04:00
internal override Exception ToJava()
{
return InnerException;
}
2006-04-10 13:09:09 +04:00
#endif
2005-08-24 15:35:00 +04:00
}
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)
{
}
#if !STATIC_COMPILER && !FIRST_PASS
2004-08-17 13:05:21 +04:00
internal override Exception ToJava()
2002-12-18 19:00:25 +03:00
{
return new java.lang.LinkageError(Message);
2002-12-18 19:00:25 +03:00
}
2006-04-10 13:09:09 +04:00
#endif
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
}
#if !STATIC_COMPILER && !FIRST_PASS
2004-08-17 13:05:21 +04:00
internal override Exception ToJava()
{
return new java.lang.VerifyError(Message);
2004-08-17 13:05:21 +04:00
}
2006-04-10 13:09:09 +04:00
#endif
2004-08-17 13:05:21 +04:00
}
class ClassNotFoundException : RetargetableJavaException
{
internal ClassNotFoundException(string name) : base(name)
{
}
#if !STATIC_COMPILER && !FIRST_PASS
2004-08-17 13:05:21 +04:00
internal override Exception ToJava()
{
return new java.lang.ClassNotFoundException(Message);
2004-08-17 13:05:21 +04:00
}
2006-04-10 13:09:09 +04:00
#endif
2004-08-17 13:05:21 +04:00
}
class ClassCircularityError : LinkageError
{
internal ClassCircularityError(string msg) : base(msg)
{
}
#if !STATIC_COMPILER && !FIRST_PASS
2004-08-17 13:05:21 +04:00
internal override Exception ToJava()
{
return new java.lang.ClassCircularityError(Message);
2004-08-17 13:05:21 +04:00
}
2006-04-10 13:09:09 +04:00
#endif
2004-08-17 13:05:21 +04:00
}
class NoClassDefFoundError : LinkageError
{
internal NoClassDefFoundError(string msg) : base(msg)
{
}
#if !STATIC_COMPILER && !FIRST_PASS
2004-08-17 13:05:21 +04:00
internal override Exception ToJava()
{
return new java.lang.NoClassDefFoundError(Message);
2004-08-17 13:05:21 +04:00
}
2006-04-10 13:09:09 +04:00
#endif
2004-08-17 13:05:21 +04:00
}
class IncompatibleClassChangeError : LinkageError
{
internal IncompatibleClassChangeError(string msg) : base(msg)
{
}
#if !STATIC_COMPILER && !FIRST_PASS
2004-08-17 13:05:21 +04:00
internal override Exception ToJava()
{
return new java.lang.IncompatibleClassChangeError(Message);
2004-08-17 13:05:21 +04:00
}
2006-04-10 13:09:09 +04:00
#endif
2004-08-17 13:05:21 +04:00
}
class IllegalAccessError : IncompatibleClassChangeError
{
internal IllegalAccessError(string msg) : base(msg)
{
}
#if !STATIC_COMPILER && !FIRST_PASS
2004-08-17 13:05:21 +04:00
internal override Exception ToJava()
{
return new java.lang.IllegalAccessError(Message);
2004-08-17 13:05:21 +04:00
}
2006-04-10 13:09:09 +04:00
#endif
2004-08-17 13:05:21 +04:00
}
class ClassFormatError : LinkageError
2004-08-17 13:05:21 +04:00
{
internal ClassFormatError(string msg, params object[] p)
: base(Format(msg, p))
2004-08-17 13:05:21 +04:00
{
}
#if !STATIC_COMPILER && !FIRST_PASS
2004-08-17 13:05:21 +04:00
internal override Exception ToJava()
{
return new java.lang.ClassFormatError(Message);
2004-08-17 13:05:21 +04:00
}
2006-04-10 13:09:09 +04:00
#endif
2004-08-17 13:05:21 +04:00
}
class UnsupportedClassVersionError : ClassFormatError
2004-08-17 13:05:21 +04:00
{
internal UnsupportedClassVersionError(string msg)
: base(msg)
{
}
#if !STATIC_COMPILER && !FIRST_PASS
2004-08-17 13:05:21 +04:00
internal override Exception ToJava()
{
return new java.lang.UnsupportedClassVersionError(Message);
2004-08-17 13:05:21 +04:00
}
2006-04-10 13:09:09 +04:00
#endif
2004-08-17 13:05:21 +04:00
}