2
Copyright (C) 2002, 2003, 2004 Jeroen Frijters
4
This software is provided 'as-is', without any express or implied
5
warranty. In no event will the authors be held liable for any damages
6
arising from the use of this software.
8
Permission is granted to anyone to use this software for any purpose,
9
including commercial applications, and to alter it and redistribute it
10
freely, subject to the following restrictions:
12
1. The origin of this software must not be misrepresented; you must not
13
claim that you wrote the original software. If you use this software
14
in a product, an acknowledgment in the product documentation would be
15
appreciated but is not required.
16
2. Altered source versions must be plainly marked as such, and must not be
17
misrepresented as being the original software.
18
3. This notice may not be removed or altered from any source distribution.
25
using System.Reflection;
27
sealed class JavaException
29
private JavaException() {}
31
private static Type Load(string clazz)
33
Tracer.Info(Tracer.Runtime, "Loading exception class: {0}", clazz);
34
TypeWrapper tw = ClassLoaderWrapper.LoadClassCritical(clazz);
39
internal static Exception ClassFormatError(string s, params object[] args)
41
return (Exception)Activator.CreateInstance(Load("java.lang.ClassFormatError"), new object[] { String.Format(s, args) });
44
internal static Exception UnsupportedClassVersionError(string s, params object[] args)
46
return (Exception)Activator.CreateInstance(Load("java.lang.UnsupportedClassVersionError"), new object[] { String.Format(s, args) });
49
internal static Exception IllegalAccessError(string s, params object[] args)
51
return (Exception)Activator.CreateInstance(Load("java.lang.IllegalAccessError"), new object[] { String.Format(s, args) });
54
internal static Exception IllegalAccessException(string s, params object[] args)
56
return (Exception)Activator.CreateInstance(Load("java.lang.IllegalAccessException"), new object[] { String.Format(s, args) });
59
internal static Exception VerifyError(string s, params object[] args)
61
return (Exception)Activator.CreateInstance(Load("java.lang.VerifyError"), new object[] { String.Format(s, args) });
64
internal static Exception IncompatibleClassChangeError(string s, params object[] args)
66
return (Exception)Activator.CreateInstance(Load("java.lang.IncompatibleClassChangeError"), new object[] { String.Format(s, args) });
69
internal static Exception ClassNotFoundException(string s, params object[] args)
71
if(JVM.IsStaticCompilerPhase1)
73
Tracer.Warning(Tracer.Compiler, "ClassNotFoundException: {0}", s);
75
return (Exception)Activator.CreateInstance(Load("java.lang.ClassNotFoundException"), new object[] { String.Format(s, args) });
78
internal static Exception NoClassDefFoundError(string s, params object[] args)
80
if(JVM.IsStaticCompilerPhase1)
82
Tracer.Warning(Tracer.Compiler, "NoClassDefFoundError: {0}", s);
84
return (Exception)Activator.CreateInstance(Load("java.lang.NoClassDefFoundError"), new object[] { String.Format(s, args) });
87
internal static Exception UnsatisfiedLinkError(string s, params object[] args)
89
return (Exception)Activator.CreateInstance(Load("java.lang.UnsatisfiedLinkError"), new object[] { String.Format(s, args) });
92
internal static Exception IllegalStateException(string s, params object[] args)
94
return (Exception)Activator.CreateInstance(Load("java.lang.IllegalStateException"), new object[] { String.Format(s, args) });
97
internal static Exception IllegalArgumentException(string s, params object[] args)
99
return (Exception)Activator.CreateInstance(Load("java.lang.IllegalArgumentException"), new object[] { String.Format(s, args) });
102
internal static Exception NegativeArraySizeException()
104
return (Exception)Activator.CreateInstance(Load("java.lang.NegativeArraySizeException"));
107
internal static Exception ArrayStoreException(string s)
109
return (Exception)Activator.CreateInstance(Load("java.lang.ArrayStoreException"), new object[] { s });
112
internal static Exception IndexOutOfBoundsException(string s)
114
return (Exception)Activator.CreateInstance(Load("java.lang.IndexOutOfBoundsException"), new object[] { s });
117
internal static Exception StringIndexOutOfBoundsException(string s)
119
return (Exception)Activator.CreateInstance(Load("java.lang.StringIndexOutOfBoundsException"), new object[] { s });
122
internal static Exception InvocationTargetException(Exception x)
124
return (Exception)Activator.CreateInstance(Load("java.lang.reflect.InvocationTargetException"), new object[] { x });
127
internal static Exception IOException(string s, params object[] args)
129
return (Exception)Activator.CreateInstance(Load("java.io.IOException"), new object[] { String.Format(s, args) });
132
internal static Exception UnknownHostException(string s, params object[] args)
134
return (Exception)Activator.CreateInstance(Load("java.net.UnknownHostException"), new object[] { String.Format(s, args) });
137
internal static Exception ArrayIndexOutOfBoundsException()
139
return (Exception)Activator.CreateInstance(Load("java.lang.ArrayIndexOutOfBoundsException"));
142
internal static Exception NumberFormatException(string s, params object[] args)
144
return (Exception)Activator.CreateInstance(Load("java.lang.NumberFormatException"), new object[] { String.Format(s, args) });
147
internal static Exception CloneNotSupportedException()
149
return (Exception)Activator.CreateInstance(Load("java.lang.CloneNotSupportedException"));
152
internal static Exception LinkageError(string s, params object[] args)
154
return (Exception)Activator.CreateInstance(Load("java.lang.LinkageError"), new object[] { String.Format(s, args) });
157
internal static Exception ClassCircularityError(string s, params object[] args)
159
return (Exception)Activator.CreateInstance(Load("java.lang.ClassCircularityError"), new object[] { String.Format(s, args) });
162
internal static Exception NullPointerException()
164
// TODO if we ever stop remapping exceptions generated in non-Java code, this needs to use
165
// reflection to get a real java.lang.NullPointerException
166
return new NullReferenceException();
169
internal static Exception ClassCastException(string s, params object[] args)
171
return (Exception)Activator.CreateInstance(Load("java.lang.ClassCastException"), new object[] { String.Format(s, args) });
174
internal static Exception NoSuchFieldError(string s, params object[] args)
176
return (Exception)Activator.CreateInstance(Load("java.lang.NoSuchFieldError"), new object[] { String.Format(s, args) });
179
internal static Exception InstantiationError(string s, params object[] args)
181
return (Exception)Activator.CreateInstance(Load("java.lang.InstantiationError"), new object[] { String.Format(s, args) });