title: Overflow or underflow in the arithmetic operation
body: <p>I am new to C#. I am getting this exception
  at the end of my program:</p>
  
  <pre><code>An unhandled exception of type 'System.ArithmeticException' occurred in mscorlib.dll
  
  Additional information: Overflow or underflow in the arithmetic operation.
  
  If there is a handler for this exception, the program may be safely continued.
  </code></pre>
  
  <p>Line where this exception is thrown really doesn't seem to be related to any arithmetical
  operations - actually I think that is the last line of my program, e.g., when it tries to exist.</p>
  
  <p>I really have no idea what went wrong. Is there a way I can defeat this issue?</p>
  
  <p>ps. call stack:</p>
  
  <pre><code>&gt;   mscorlib.dll!double.IsPositiveInfinity(double d) + 0xc bytes    
      PresentationFramework.dll!System.Windows.Window.ValidateTopLeft(double length) + 0x25 bytes 
      PresentationFramework.dll!System.Windows.Window.CoerceTop(System.Windows.DependencyObject d, object value) + 0x64 bytes 
      WindowsBase.dll!System.Windows.DependencyObject.ProcessCoerceValue(System.Windows.DependencyProperty dp, System.Windows.PropertyMetadata metadata, ref System.Windows.EntryIndex entryIndex, ref int targetIndex, ref System.Windows.EffectiveValueEntry newEntry, ref System.Windows.EffectiveValueEntry oldEntry, ref object oldValue, object baseValue, object controlValue, System.Windows.CoerceValueCallback coerceValueCallback, bool coerceWithDeferredReference, bool coerceWithCurrentValue, bool skipBaseValueChecks) + 0x55 bytes   
      WindowsBase.dll!System.Windows.DependencyObject.UpdateEffectiveValue(System.Windows.EntryIndex entryIndex, System.Windows.DependencyProperty dp, System.Windows.PropertyMetadata metadata, System.Windows.EffectiveValueEntry oldEntry, ref System.Windows.EffectiveValueEntry newEntry, bool coerceWithDeferredReference, bool coerceWithCurrentValue, System.Windows.OperationType operationType) + 0x247 bytes   
      WindowsBase.dll!System.Windows.DependencyObject.CoerceValue(System.Windows.DependencyProperty dp) + 0xd5 bytes  
      PresentationFramework.dll!System.Windows.Window.SetupInitialState(double requestedTop, double requestedLeft, double requestedWidth, double requestedHeight) + 0x135 bytes   
      PresentationFramework.dll!System.Windows.Window.CreateSourceWindow(bool duringShow) + 0x30b bytes   
      PresentationFramework.dll!System.Windows.Window.CreateSourceWindowDuringShow() + 0xa bytes  
      PresentationFramework.dll!System.Windows.Window.SafeCreateWindowDuringShow() + 0x3f bytes   
      PresentationFramework.dll!System.Windows.Window.ShowHelper(object booleanBox) + 0x77 bytes  
      WindowsBase.dll!System.Windows.Threading.ExceptionWrapper.InternalRealCall(System.Delegate callback, object args, int numArgs) + 0x56 bytes 
      WindowsBase.dll!MS.Internal.Threading.ExceptionFilterHelper.TryCatchWhen(object source, System.Delegate method, object args, int numArgs, System.Delegate catchHandler) + 0x3a bytes    
      WindowsBase.dll!System.Windows.Threading.DispatcherOperation.InvokeImpl() + 0xac bytes  
      WindowsBase.dll!System.Windows.Threading.DispatcherOperation.InvokeInSecurityContext(object state) + 0x38 bytes 
      mscorlib.dll!System.Threading.ExecutionContext.RunInternal(System.Threading.ExecutionContext executionContext, System.Threading.ContextCallback callback, object state, bool preserveSyncCtx) + 0xa7 bytes  
      mscorlib.dll!System.Threading.ExecutionContext.Run(System.Threading.ExecutionContext executionContext, System.Threading.ContextCallback callback, object state, bool preserveSyncCtx) + 0x16 bytes  
      mscorlib.dll!System.Threading.ExecutionContext.Run(System.Threading.ExecutionContext executionContext, System.Threading.ContextCallback callback, object state) + 0x41 bytes    
      WindowsBase.dll!System.Windows.Threading.DispatcherOperation.Invoke() + 0x5b bytes  
      WindowsBase.dll!System.Windows.Threading.Dispatcher.ProcessQueue() + 0x16b bytes    
      WindowsBase.dll!System.Windows.Threading.Dispatcher.WndProcHook(System.IntPtr hwnd, int msg, System.IntPtr wParam, System.IntPtr lParam, ref bool handled) + 0x5a bytes 
      WindowsBase.dll!MS.Win32.HwndWrapper.WndProc(System.IntPtr hwnd, int msg, System.IntPtr wParam, System.IntPtr lParam, ref bool handled) + 0x9b bytes    
      WindowsBase.dll!MS.Win32.HwndSubclass.DispatcherCallbackOperation(object o) + 0x6b bytes    
      WindowsBase.dll!System.Windows.Threading.ExceptionWrapper.InternalRealCall(System.Delegate callback, object args, int numArgs) + 0x56 bytes 
      WindowsBase.dll!MS.Internal.Threading.ExceptionFilterHelper.TryCatchWhen(object source, System.Delegate method, object args, int numArgs, System.Delegate catchHandler) + 0x3a bytes    
      WindowsBase.dll!System.Windows.Threading.Dispatcher.LegacyInvokeImpl(System.Windows.Threading.DispatcherPriority priority, System.TimeSpan timeout, System.Delegate method, object args, int numArgs) + 0x10e bytes 
      WindowsBase.dll!MS.Win32.HwndSubclass.SubclassWndProc(System.IntPtr hwnd, int msg, System.IntPtr wParam, System.IntPtr lParam) + 0xf1 bytes 
      [Native to Managed Transition]  
      [Managed to Native Transition]  
      WindowsBase.dll!System.Windows.Threading.Dispatcher.PushFrameImpl(System.Windows.Threading.DispatcherFrame frame) + 0xae bytes  
      WindowsBase.dll!System.Windows.Threading.Dispatcher.PushFrame(System.Windows.Threading.DispatcherFrame frame) + 0x49 bytes  
      WindowsBase.dll!System.Windows.Threading.Dispatcher.Run() + 0x4b bytes  
      PresentationFramework.dll!System.Windows.Application.RunDispatcher(object ignore) + 0x17 bytes  
      PresentationFramework.dll!System.Windows.Application.RunInternal(System.Windows.Window window) + 0x6f bytes 
      PresentationFramework.dll!System.Windows.Application.Run(System.Windows.Window window) + 0x26 bytes 
      PresentationFramework.dll!System.Windows.Application.Run() + 0x1b bytes 
      CardReaderGui.exe!CardReaderGui.App.Main() + 0x59 bytes C#
      [Native to Managed Transition]  
      [Managed to Native Transition]  
      mscorlib.dll!System.AppDomain.ExecuteAssembly(string assemblyFile, System.Security.Policy.Evidence assemblySecurity, string[] args) + 0x6b bytes    
      Microsoft.VisualStudio.HostingProcess.Utilities.dll!Microsoft.VisualStudio.HostingProcess.HostProc.RunUsersAssembly() + 0x27 bytes  
      mscorlib.dll!System.Threading.ThreadHelper.ThreadStart_Context(object state) + 0x6f bytes   
      mscorlib.dll!System.Threading.ExecutionContext.RunInternal(System.Threading.ExecutionContext executionContext, System.Threading.ContextCallback callback, object state, bool preserveSyncCtx) + 0xa7 bytes  
      mscorlib.dll!System.Threading.ExecutionContext.Run(System.Threading.ExecutionContext executionContext, System.Threading.ContextCallback callback, object state, bool preserveSyncCtx) + 0x16 bytes  
      mscorlib.dll!System.Threading.ExecutionContext.Run(System.Threading.ExecutionContext executionContext, System.Threading.ContextCallback callback, object state) + 0x41 bytes    
      mscorlib.dll!System.Threading.ThreadHelper.ThreadStart() + 0x44 bytes   
      [Native to Managed Transition]  
  </code></pre>