2003-03-26 Zoltan Varga <vargaz@freemail.hu>
authorZoltan Varga <vargaz@gmail.com>
Wed, 26 Mar 2003 18:20:26 +0000 (18:20 -0000)
committerZoltan Varga <vargaz@gmail.com>
Wed, 26 Mar 2003 18:20:26 +0000 (18:20 -0000)
* ILGenerator.cs: Implemented ThrowException.

svn path=/trunk/mcs/; revision=12855

mcs/class/corlib/System.Reflection.Emit/ChangeLog
mcs/class/corlib/System.Reflection.Emit/ILGenerator.cs

index 5af87433770f73528cc9dfbce994938c5c81063c..e6ab20dd10157333c5f923b7d6a3b3a27703101f 100644 (file)
@@ -1,3 +1,7 @@
+2003-03-26  Zoltan Varga  <vargaz@freemail.hu>
+
+       * ILGenerator.cs: Implemented ThrowException.
+
 2003-03-10  Zoltan Varga  <vargaz@freemail.hu>
 
        * ILGenerator.cs: Propagate maxstack info along branches.
index bc1874d8aed73f33a2398ef3ae2ca236c9857870..c6e1c7b47a6caa2ee8c8167a30b847e1c05750de 100644 (file)
@@ -643,9 +643,20 @@ namespace System.Reflection.Emit {
 
                        sym_writer.MarkSequencePoint (code_len, startLine, startColumn);
                }
+
                public virtual void ThrowException (Type exceptionType) {
-                       throw new NotImplementedException ();
+                       if (exceptionType == null)
+                               throw new ArgumentNullException ("exceptionType");
+                       if (! ((exceptionType == typeof (Exception)) || 
+                                  exceptionType.IsSubclassOf (typeof (Exception))))
+                               throw new ArgumentException ("Type should be an exception type", "exceptionType");
+                       ConstructorInfo ctor = exceptionType.GetConstructor (new Type[0]);
+                       if (ctor == null)
+                               throw new ArgumentException ("Type should have a default constructor", "exceptionType");
+                       Emit (OpCodes.Newobj, ctor);
+                       Emit (OpCodes.Throw);
                }
+
                public void UsingNamespace (String usingNamespace) {
                        throw new NotImplementedException ();
                }