Question: - Program has to be written in C# You Do It Purposely Causing Exceptions Ctt generates SystemExceptions automatically under many circumstances. In the next steps,



- Program has to be written in C#
You Do It Purposely Causing Exceptions Ctt generates SystemExceptions automatically under many circumstances. In the next steps, you purposely generate a SystemException by executing a program that provides multiple opportunities for Exceptions 1. Start a new project named ExceptionsOnPurpose, and type the following program, which allows you to generate several different Exceptions. using System; using static System.Console; class ExceptionsonPurpose static void MainO int answer; int result; int zero = 0; WriteC"Enter an integer >> answer = Convert.ToInt32(ReadLine()); result answer / zero; WriteLine('The answer is"answer) 2. You cannot divide by the unnamed constant 0 (by changing the dividing statement to result-answer/0;), nor can you change the variable zero to a named constant (by inserting const at the start of the int zero declaration). If you made either of these changes, the program would not compile because the compiler can determine that division by zero will occur. Using a variable zero instead of either an unnamed or named constant, however, the compiler "trusts" that a legitimate value will be provided for the variable before division occurs (although in this case, the trust is not warranted). Save the program, and compile it. 3. Execute the program several times using different input values, and observe the results. Two windows appear with each execution. The first reports that Windows is collecting more information about the problem. This window is soon replaced with the one shown in Figure 11-3, which repeats that continues)
Step by Step Solution
There are 3 Steps involved in it
Get step-by-step solutions from verified subject matter experts
