示例#1
0
	public static int test_0_nonvirt_nullref_at_clause_start () {
		ExceptionTests t = null;
		try {
			t.amethod ();
		} catch (NullReferenceException) {
			return 0;
		}

		return 1;
	}
 /// <summary>
 /// Method to perform second task of training.
 /// Generates IndexOutOfRangeException.
 /// </summary>
 private void IndexOutOfRangeTask()
 {
     try
     {
         this.Writer.WriteLine("\nTask 2: IndexoutOfRangeException");
         ExceptionTests.IndexOutOfRange();
     }
     catch (IndexOutOfRangeException e)
     {
         this.Writer.WriteLine(e.Message);
         this.Logger.LogMessage($"Class - SecondTrainingRunner | Method - IndexOutOfRange | {e.Message}");
     }
 }
 /// <summary>
 /// Method to perform first task of training.
 /// Generates StackOverflowException
 /// </summary>
 /// <exception cref="StackOverflowException">Generates if user inputs "y"</exception>>
 private void OverflowTask()
 {
     try
     {
         this.Writer.WriteLine("\nTask 1: StackOverflowException");
         this.Writer.Write("\nGenerate StackOverflowException? (y/n): ");
         if (this.Reader.ReadLine() == "y")
         {
             ExceptionTests.StackOverflow();
         }
     }
     catch (StackOverflowException e)
     {
         this.Writer.WriteLine(e.Message);
         this.Logger.LogMessage($"Class - SecondTrainingRunner | Method - OverflowTask | {e.Message}");
     }
 }
 /// <summary>
 /// Method to perform third task of training.
 /// Generates ArgumentException.
 /// </summary>
 private void ArgumentExcTask()
 {
     try
     {
         this.Writer.WriteLine("\nTask 3: ArgumentException");
         ExceptionTests.DoSomeMath(-1, 2);
     }
     catch (ArgumentException e)
         when(e.ParamName == "a")
         {
             this.Writer.WriteLine(e.Message);
             this.Logger.LogMessage($"Class - SecondTrainingRunner | Method - ArgumentExcTask | {e.Message}");
         }
     catch (ArgumentException e)
         when(e.ParamName == "b")
         {
             this.Writer.WriteLine(e.Message);
             this.Logger.LogMessage($"Class - SecondTrainingRunner | Method - ArgumentExcTask | {e.Message}");
         }
 }