2 // ExceptionTest.cs - NUnit Test Cases for the System.Exception class
\r
5 // Linus Upson (linus@linus.com)
\r
6 // Duncan Mak (duncan@ximian.com)
\r
8 // Copyright (C) 2004-2005 Novell, Inc (http://www.novell.com)
12 using System.Runtime.Serialization;
14 using NUnit.Framework;
\r
16 namespace MonoTests.System
\r
18 public class ExceptionTest : TestCase
\r
20 public ExceptionTest() {}
\r
22 // This test makes sure that exceptions thrown on block boundaries are
\r
23 // handled in the correct block. The meaning of the 'caught' variable is
\r
24 // a little confusing since there are two catchers: the method being
\r
25 // tested the the method calling the test. There is probably a better
\r
26 // name, but I can't think of it right now.
\r
29 public void TestThrowOnBlockBoundaries()
\r
39 Assert("Exceptions thrown before try blocks should not be caught", caught);
\r
43 ThrowAtBeginOfTry();
\r
47 Assert("Exceptions thrown at begin of try blocks should be caught", !caught);
\r
55 Assert("Exceptions thrown at end of try blocks should be caught", !caught);
\r
59 ThrowAtBeginOfCatch();
\r
63 Assert("Exceptions thrown at begin of catch blocks should not be caught", caught);
\r
67 ThrowAtEndOfCatch();
\r
71 Assert("Exceptions thrown at end of catch blocks should not be caught", caught);
\r
75 ThrowAtBeginOfFinally();
\r
79 Assert("Exceptions thrown at begin of finally blocks should not be caught", caught);
\r
83 ThrowAtEndOfFinally();
\r
87 Assert("Exceptions thrown at end of finally blocks should not be caught", caught);
\r
91 ThrowAfterFinally();
\r
95 Assert("Exceptions thrown after finally blocks should not be caught", caught);
\r
98 private static void DoNothing()
\r
102 private static void ThrowException()
\r
104 throw new Exception();
\r
107 private static void ThrowBeforeTry()
\r
112 } catch (Exception) {
\r
117 private static void ThrowAtBeginOfTry()
\r
123 } catch (Exception) {
\r
128 private static void ThrowAtEndOfTry()
\r
134 } catch (Exception) {
\r
139 private static void ThrowAtBeginOfCatch()
\r
145 } catch (Exception) {
\r
150 private static void ThrowAtEndOfCatch()
\r
156 } catch (Exception) {
\r
162 private static void ThrowAtBeginOfFinally()
\r
168 } catch (Exception) {
\r
176 private static void ThrowAtEndOfFinally()
\r
182 } catch (Exception) {
\r
190 private static void ThrowAfterFinally()
\r
196 } catch (Exception) {
\r
205 public void InnerExceptionSource ()
\r
207 Exception a = new Exception ("a", new ArgumentException ("b"));
\r
210 AssertEquals (null, a.InnerException.Source);
\r
214 [ExpectedException (typeof (ArgumentNullException))]
215 public void GetObjectData_Null ()
217 Exception e = new Exception ();
218 e.GetObjectData (null, new StreamingContext (StreamingContextStates.All));
\r