Example

The following example demonstrates catching an exception type that derives from ApplicationException. There is, however, no valid scenerio for catching an ApplicationException type.

using System;
using System.Reflection;

namespace Samples
{
  public class ApplicationExceptionSample
  {
    public static void Main()
    {
      try
      {
        Type t = typeof(string);
        MethodInfo m = t.GetMethod("EndsWith");
        string s = "Hello world!";
        object[] arguments = {"world!", "!"};
        Console.WriteLine(m.Invoke(s, arguments));
      }
      catch(ApplicationException e)
      {
        Console.WriteLine("Exception: {0}", e);
      }
    }
  }
}
The output is
 Exception: System.Reflection.TargetParameterCountException: Parameter count mismatch. at System.Reflection.RuntimeMethodInfo.InternalInvoke(Object obj, BindingFlags ...

Get .NET Framework Standard Library Annotated Reference, Volume 1: Base Class Library and Extended Numerics Library now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.