Question: The code above shows an Account class with properties to hold the account owner's names and account balance. The Withdraw method deducts the withdrawal amount

 The code above shows an Account class with properties to hold

The code above shows an Account class with properties to hold the account owner's names and account balance. The Withdraw method deducts the withdrawal amount from the balance, and if the withdrawal amount is higher than the balance, it throws an exception - the InvalidOperationException. When the exception is raised, it cancels the withdraw transaction and signals to the application that the account cannot be debited of that amount because of insufficient funds. Thus, the InvalidOperationException exception is thrown in cases where the failure to invoke a method is caused by reasons other than invalid arguments. Because the InvalidOperationException exception can be thrown in a wide variety of circumstances, it is important to read the exception message returned by the Message property. How you handle the exception depends on the specific situation. Most commonly, however, the exception results from your own or user's incorrect actions, and therefore it can be anticipated and avoided. 3. Create a new C# Console Application project and import (replacing the existing file) the Program. cs file attached to this task. The main Program class, and specifically its Main method, should sequentially address every exception from the list via a block of program code (if applicable) placed inside the 'try' section of the respective "try-catch' statement. For instance, our example given for the InvalidOperationException exception type can be written as follows: try Account account = new Account ("Sergey", "P. ", 160); account . Withdraw (1000) ; catch (InvalidOperationException exception) Console. WriteLine("The following error detected: " + exception. GetType() . ToString()+ " with message \\"" + exception.Message+"\\""); This code prints the following message to the terminal: The following error detected: System. InvalidoperationException with message "Insufficient fund" Note that the 'try' section of the block must contain code that causes the error expected in the ' catch' section. In our case, the account. Withdraw(1000) will throw the InvalidOperationException exception, which then will be handled in the 'catch' section. Furthermore, if you need to add an auxiliary class (e.g. the Account class in our example), then place it inside the Program. cs file next to the existing Program class. For your convenience, we provide a template of Program. cs containing our example. Note that for some exceptions you do not need to provide a program code but your text answer in the report. We do not specify here the particular exception from the list because we expect you to give a clear reason for omitting it. 4. We expect you to answer the questions in the text report and write the associated code examples in the Program. cs file. Every exception must be discussed in no more than half a page of text. Your solution should be concise and answer the relevant questions exactly. Remember that you must explain solutions in your words; that is, copying blocks of text from the Internet is never acceptable. Though you are allowed to paraphrase answers found in the Internet, be prepared to explain them during the one-on- one interview with your tutor

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related General Management Questions!