~ubuntu-branches/ubuntu/dapper/ikvm/dapper

« back to all changes in this revision

Viewing changes to runtime/JavaException.cs

  • Committer: Bazaar Package Importer
  • Author(s): John Goerzen
  • Date: 2004-08-26 10:18:19 UTC
  • Revision ID: james.westby@ubuntu.com-20040826101819-plz8au2mx4uk1cvc
Tags: upstream-0.8.0.0
ImportĀ upstreamĀ versionĀ 0.8.0.0

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
/*
 
2
  Copyright (C) 2002, 2003, 2004 Jeroen Frijters
 
3
 
 
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.
 
7
 
 
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:
 
11
 
 
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.
 
19
 
 
20
  Jeroen Frijters
 
21
  jeroen@frijters.net
 
22
  
 
23
*/
 
24
using System;
 
25
using System.Reflection;
 
26
 
 
27
sealed class JavaException
 
28
{
 
29
        private JavaException() {}
 
30
 
 
31
        private static Type Load(string clazz)
 
32
        {
 
33
                Tracer.Info(Tracer.Runtime, "Loading exception class: {0}", clazz);
 
34
                TypeWrapper tw = ClassLoaderWrapper.LoadClassCritical(clazz);
 
35
                tw.Finish();
 
36
                return tw.TypeAsTBD;
 
37
        }
 
38
 
 
39
        internal static Exception ClassFormatError(string s, params object[] args)
 
40
        {
 
41
                return (Exception)Activator.CreateInstance(Load("java.lang.ClassFormatError"), new object[] { String.Format(s, args) });
 
42
        }
 
43
 
 
44
        internal static Exception UnsupportedClassVersionError(string s, params object[] args)
 
45
        {
 
46
                return (Exception)Activator.CreateInstance(Load("java.lang.UnsupportedClassVersionError"), new object[] { String.Format(s, args) });
 
47
        }
 
48
 
 
49
        internal static Exception IllegalAccessError(string s, params object[] args)
 
50
        {
 
51
                return (Exception)Activator.CreateInstance(Load("java.lang.IllegalAccessError"), new object[] { String.Format(s, args) });
 
52
        }
 
53
 
 
54
        internal static Exception IllegalAccessException(string s, params object[] args)
 
55
        {
 
56
                return (Exception)Activator.CreateInstance(Load("java.lang.IllegalAccessException"), new object[] { String.Format(s, args) });
 
57
        }
 
58
 
 
59
        internal static Exception VerifyError(string s, params object[] args)
 
60
        {
 
61
                return (Exception)Activator.CreateInstance(Load("java.lang.VerifyError"), new object[] { String.Format(s, args) });
 
62
        }
 
63
 
 
64
        internal static Exception IncompatibleClassChangeError(string s, params object[] args)
 
65
        {
 
66
                return (Exception)Activator.CreateInstance(Load("java.lang.IncompatibleClassChangeError"), new object[] { String.Format(s, args) });
 
67
        }
 
68
 
 
69
        internal static Exception ClassNotFoundException(string s, params object[] args)
 
70
        {
 
71
                if(JVM.IsStaticCompilerPhase1)
 
72
                {
 
73
                        Tracer.Warning(Tracer.Compiler, "ClassNotFoundException: {0}", s);
 
74
                }
 
75
                return (Exception)Activator.CreateInstance(Load("java.lang.ClassNotFoundException"), new object[] { String.Format(s, args) });
 
76
        }
 
77
 
 
78
        internal static Exception NoClassDefFoundError(string s, params object[] args)
 
79
        {
 
80
                if(JVM.IsStaticCompilerPhase1)
 
81
                {
 
82
                        Tracer.Warning(Tracer.Compiler, "NoClassDefFoundError: {0}", s);
 
83
                }
 
84
                return (Exception)Activator.CreateInstance(Load("java.lang.NoClassDefFoundError"), new object[] { String.Format(s, args) });
 
85
        }
 
86
 
 
87
        internal static Exception UnsatisfiedLinkError(string s, params object[] args)
 
88
        {
 
89
                return (Exception)Activator.CreateInstance(Load("java.lang.UnsatisfiedLinkError"), new object[] { String.Format(s, args) });
 
90
        }
 
91
 
 
92
        internal static Exception IllegalStateException(string s, params object[] args)
 
93
        {
 
94
                return (Exception)Activator.CreateInstance(Load("java.lang.IllegalStateException"), new object[] { String.Format(s, args) });
 
95
        }
 
96
 
 
97
        internal static Exception IllegalArgumentException(string s, params object[] args)
 
98
        {
 
99
                return (Exception)Activator.CreateInstance(Load("java.lang.IllegalArgumentException"), new object[] { String.Format(s, args) });
 
100
        }
 
101
 
 
102
        internal static Exception NegativeArraySizeException()
 
103
        {
 
104
                return (Exception)Activator.CreateInstance(Load("java.lang.NegativeArraySizeException"));
 
105
        }
 
106
 
 
107
        internal static Exception ArrayStoreException(string s)
 
108
        {
 
109
                return (Exception)Activator.CreateInstance(Load("java.lang.ArrayStoreException"), new object[] { s });
 
110
        }
 
111
 
 
112
        internal static Exception IndexOutOfBoundsException(string s)
 
113
        {
 
114
                return (Exception)Activator.CreateInstance(Load("java.lang.IndexOutOfBoundsException"), new object[] { s });
 
115
        }
 
116
 
 
117
        internal static Exception StringIndexOutOfBoundsException(string s)
 
118
        {
 
119
                return (Exception)Activator.CreateInstance(Load("java.lang.StringIndexOutOfBoundsException"), new object[] { s });
 
120
        }
 
121
 
 
122
        internal static Exception InvocationTargetException(Exception x)
 
123
        {
 
124
                return (Exception)Activator.CreateInstance(Load("java.lang.reflect.InvocationTargetException"), new object[] { x });
 
125
        }
 
126
 
 
127
        internal static Exception IOException(string s, params object[] args)
 
128
        {
 
129
                return (Exception)Activator.CreateInstance(Load("java.io.IOException"), new object[] { String.Format(s, args) });
 
130
        }
 
131
 
 
132
        internal static Exception UnknownHostException(string s, params object[] args)
 
133
        {
 
134
                return (Exception)Activator.CreateInstance(Load("java.net.UnknownHostException"), new object[] { String.Format(s, args) });
 
135
        }
 
136
 
 
137
        internal static Exception ArrayIndexOutOfBoundsException()
 
138
        {
 
139
                return (Exception)Activator.CreateInstance(Load("java.lang.ArrayIndexOutOfBoundsException"));
 
140
        }
 
141
 
 
142
        internal static Exception NumberFormatException(string s, params object[] args)
 
143
        {
 
144
                return (Exception)Activator.CreateInstance(Load("java.lang.NumberFormatException"), new object[] { String.Format(s, args) });
 
145
        }
 
146
 
 
147
        internal static Exception CloneNotSupportedException()
 
148
        {
 
149
                return (Exception)Activator.CreateInstance(Load("java.lang.CloneNotSupportedException"));
 
150
        }
 
151
 
 
152
        internal static Exception LinkageError(string s, params object[] args)
 
153
        {
 
154
                return (Exception)Activator.CreateInstance(Load("java.lang.LinkageError"), new object[] { String.Format(s, args) });
 
155
        }
 
156
 
 
157
        internal static Exception ClassCircularityError(string s, params object[] args)
 
158
        {
 
159
                return (Exception)Activator.CreateInstance(Load("java.lang.ClassCircularityError"), new object[] { String.Format(s, args) });
 
160
        }
 
161
 
 
162
        internal static Exception NullPointerException()
 
163
        {
 
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();
 
167
        }
 
168
 
 
169
        internal static Exception ClassCastException(string s, params object[] args)
 
170
        {
 
171
                return (Exception)Activator.CreateInstance(Load("java.lang.ClassCastException"), new object[] { String.Format(s, args) });
 
172
        }
 
173
 
 
174
        internal static Exception NoSuchFieldError(string s, params object[] args)
 
175
        {
 
176
                return (Exception)Activator.CreateInstance(Load("java.lang.NoSuchFieldError"), new object[] { String.Format(s, args) });
 
177
        }
 
178
 
 
179
        internal static Exception InstantiationError(string s, params object[] args)
 
180
        {
 
181
                return (Exception)Activator.CreateInstance(Load("java.lang.InstantiationError"), new object[] { String.Format(s, args) });
 
182
        }
 
183
}