System.Exception—catch an ArithmeticException

Microsoft .NET Framework, ASP.NET, Visual C# (CSharp, C Sharp, C-Sharp) Developer Training, Visual Studio


Jump to: navigation, search
C# Code Snippets

C# Source Code Bank

See also …
edit

This C# code snippet first causes and then catches an ArithmeticException .

using System;
 
class ArithmeticExceptionExample
{
   public static void Main()
   {
      try
      {
         Math.Sign (Single.NaN);
      }
      catch (ArithmeticException e)
      {
        Console.WriteLine ("Exception: {0}", e);
      }
    }
}


 ArithmeticException example (program output)
Exception: System.ArithmeticException:
Function does not accept floating point Not-a-Number values.
at System.Math.Sign(Single value)
at ArithmeticExceptionExample.Main() in Program.cs:line 6



Personal tools