Example

using System;

namespace Samples
{
  public class DivideByZeroExceptionSample
  {
    public static void Main()
    {
      try
      {
        int i = 0;
        Console.WriteLine(42 / i);
      }
      catch(DivideByZeroException e)
      {
        Console.WriteLine("Exception: {0}", e);
      }
    }
  }
}
The output is
Exception: System.DivideByZeroException: Attempted to divide by zero.
   at Samples.DivideByZeroExceptionSample.Main() in C:\Books\BCL\Samples\
System\DivideByZeroException\DivideByZeroException.cs:line 12

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.