Question: Need this in JavaScript & PHP, please. This is my 4th time sending this back. Please make sure it works. Assessment Requirements Print to the

Need this in JavaScript & PHP, please. This is my 4th time sending this back. Please make sure it works.

Assessment Requirements

Print to the console the following messages:

Assessment 7 Logging Exceptionsto a File.

Testing Try/Catch for Divide by Zero, File Does Not Exist, Array Out of Bounds, and Array is Null scenarios.

All console error messages are printed from error log file.

Create a logfile. Redirect the stdErr stream to write to your logfile.

Create a function, DisplayLogfile(), that will read the logfile and display to the console.

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 item 6 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.

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

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

Create a try/catch block.

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

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

Create a try/catch block.

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

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

Create a try/catch block.

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

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.

Assessment 7 Logging Exceptions to a File.

Testing Try/Catch for Divide by Zero, File Does Not Exist, Array Out of Bounds, and Array is Null scenarios. All console error messages are printed from error log 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 Databases Questions!