12.3. Example: Divide by Zero Without Exception Handling

First we demonstrate what happens when errors arise in a console application that does not use exception handling. Figure 12.1 inputs two integers from the user, then divides the first integer by the second using integer division to obtain an Integer result. In this example, we will see that an exception is thrown (i.e., an exception occurs) when a method detects a problem and is unable to handle it.

Figure 12.1. Integer division without exception handling.
					1
					' Fig. 12.1: DivideByZeroNoExceptionHandling.vb
					2
					' An application that attempts to divide by zero.
					3
					Module DivideByZeroNoExceptionHandling
 4
					Sub Main()
 5
					' get numerator and denominator
					6        Console.Write("Please enter an integer numerator: ...

Get Visual Basic 2005 for Programmers: Deitel Developer Series, Second Edition 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.