Question: You will complete an single program containing multiple tasks to demonstrate the skills presented in this lesson for your selected language path. Please keep in

You will complete an single program containing multiple tasks to demonstrate the skills presented in this lesson for your selected language path. Please keep in mind that with all the assignments in this course, any given scenarios are hypothetical and intended solely to demonstrate specific skills.

The source code file is the file in your project that contains the code you wrote. You will only need to submit the source code file for your program and not the entire project folder or any additional project files. Below are listed the file extensions for the source code file for each language:

.cs file for C#

.java file for Java

.php and .js files for Web Development

Note: If your language of choice is Web Development, you will need to complete the exercises in both PHP and JavaScript.

Using the language in which you have chosen to focus: C#, Java, Web Development languages (PHP and JavaScript), please complete the following Assignment:

Assignment Requirements

  1. Print to the console the following messages:
  • "Assignment 7 - Logging Exceptionsto a File."
  • "TestingTry/CatchforDividebyZero,FileDoesNot Exist,ArrayOutofBounds,andArrayisNullscenarios."
  • "Allconsoleerrormessagesareprintedfromerrorlog file."
  1. Createalogfile.RedirectthestdErrstreamtowritetoyourlogfile.
  2. Createafunction,DisplayLogfile(),thatwillreadthelogfileanddisplayto theconsole.
  3. Create a function named, DivideByZero(), which will attempt to divide a number by 0.
  4. Create a function named, FileDoesNotExist(), which will attempt to open a non-existent file named, "NoFileNamedThis.txt".
  5. Create a function named, ArrayOutOfBounds(), which will create an array and then try to access a non-existent index in that an array.(Hint:If there are 5 items in the array then the code might try to access item6 for instance.)
  6. Create a function named ArrayIsNull(), which will create an array and then set it equal to null before trying to access an item in the array.
  7. Create a try/catch block.

a) From the try portion, call the function, DivideByZero().

b) In the catch portion, write the error message contained in the

exception object to the standard error stream.

  1. Create a try/catch block.

a) From the try portion, call the function, FileDoesNotExist().

b) In the catch portion, write the error message contained in the

exception object to the standard error stream.

  1. Create a try/catch block.

a) From the try portion, call the function, ArrayOutOfBounds().

b) In the catch portion, write the error message contained in the

exception object to the standard error stream.

  1. Create a try/catch block.

a) From the try portion, call the function, ArrayIsNull().

b) In the catch portion, write the error message contained in the exception object to the standard error stream.

  1. Call the DisplayLogFile() function to display the contents of the log file your program has created.

EXPECTED OUTPUT

Note: Error messages might differ from language to language and the file path as well.

Assignment 7 - Logging Exceptions to a File.

TestingTry/CatchforDividebyZero,FileDoesNot Exist,ArrayOutofBounds,andArrayisNullscenarios.

Allconsoleerrormessagesareprintedfromerrorlog file.

Attempted to divide by zero.

Could not find file 'C:\NoFileNamedThis.txt'

Index was outside the bounds of the array.

Object reference not set to an instance of an object.

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 Mathematics Questions!