O'Reilly logo

Visual C#® 2012: How to Program, Fifth Edition by Harvey Deitel, Paul Deitel

Stay ahead with the world's most comprehensive technology and business learning platform.

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, tutorials, and more.

Start Free Trial

No credit card required

13.2. Example: Divide by Zero without Exception Handling

Let’s revisit what happens when errors arise in a console app that does not use exception handling. Figure 13.1 inputs two integers from the user, then divides the first integer by the second using integer division to obtain an int result. In this example, an exception is thrown (i.e., an exception occurs) when a method detects a problem and is unable to handle it.

 1   // Fig. 13.1: DivideByZeroNoExceptionHandling.cs  2   // Integer division without exception handling.  3   using System;  4  5   class DivideByZeroNoExceptionHandling  6   {  7      static void Main()  8      {  9         // get numerator 10         Console.Write( "Please enter an integer ...

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, interactive tutorials, and more.

Start Free Trial

No credit card required