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
- Print to the console the following messages:
- "Assignment 7 - Logging Exceptionsto a File."
- "TestingTry/CatchforDividebyZero,FileDoesNot Exist,ArrayOutofBounds,andArrayisNullscenarios."
- "Allconsoleerrormessagesareprintedfromerrorlog file."
- Createalogfile.RedirectthestdErrstreamtowritetoyourlogfile.
- Createafunction,DisplayLogfile(),thatwillreadthelogfileanddisplayto theconsole.
- Create a function named, DivideByZero(), which will attempt to divide a number by 0.
- Create a function named, FileDoesNotExist(), which will attempt to open a non-existent file named, "NoFileNamedThis.txt".
- 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.)
- 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.
- 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.
- 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.
- 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.
- 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.
- 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
Get step-by-step solutions from verified subject matter experts
