Description
Unit 6 Assignment: Exception and Error Handling
Outcomes addressed in this activity:
Unit Outcomes:
Differentiate between errors and exceptions.
Select appropriate methods for handling exceptions and errors.
Implement an Assert statement.
Implement a Try/Catch statement.
Course Outcome:
IT232-3: Select appropriate secure data handling techniques.
Purpose
The purpose of this assignment is to provide you with an opportunity to demonstrate knowledge of using exception handling tools such as assert statements and try/catch blocks.
Assignment Instructions
You will complete a single program containing multiple sections to demonstrate the skills presented in this lesson for your chosen 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:
The program for this assignment will consist of four sections, each headed by the three-line comment below:
//*********************************************************
//****Assignment 6 Section X
//*********************************************************
(where X stands for the portion of the assignment to follow.)
Assignment Requirements
Section 1:
Enter the comment with the section title as described above.
Print to the console the message, “Assignment 6 – Asserts and Try/Catch.”
Create a string variable and set its value to null or empty.
Create an integer variable and set it to 0.
Note: The variables above are initialized to values intended to trigger the following assert statements.
Create an assert statement to validate that the string variable is not empty or null with the message, “Parameter must not be empty or null.”
Create an assert statement to validate that the integer variable is greater than zero with the message, “Parameter must be greater than zero.”
Section 2:
Enter the comment with the section title as described above.
You will create an array of strings.
You will create a try/catch block.
In the try portion of the try/catch, you will loop through the array using a ‘for loop’ where your index variable begins at 0 and the loop continues as long as the index is <=the length of the array. This will cause an array out of bounds error where the loop attempts to access an array index value that is one more than the last item.
The catch portion will catch the out of bounds exception. Inside the catch block you will write two lines to the console. The first simply prints the string, “Array out of bounds error occurred.” On a new line you will then print the error message contained in the exception object.
Section 3:
Enter the comment with the section title as described above.
You will create a try/catch block.
In the try portion of the try/catch, you will attempt to open a non-existent file named, “NoFileNamedThis.txt”.
The catch portion will catch the file not found exception. Inside the catch block you will write two lines to the console. The first simply prints the string, “File not found error.” On a new line you will then print the error message contained in the exception object.
Section 4:
Enter the comment with the section title as described above.
You will create a function called, “DivideByZero”, which will allow for two integer operands, dividend and divisor.
The function will check to be sure the divisor is not equal to zero.
If the divisor is equal to 0 then the function will throw an exception with the message, “Divide by Zero.”
You will create a try/catch block.
In the try portion you will call the function, DivideByZero, and pass it two numbers with the second being 0 to cause an error.
The catch portion will catch the Divide By Zero exception thrown by the function. Inside the catch block you will write two lines to the console. The first simply prints the string, “DivideByZero error occurred.” On a new line you will then print the error message contained in the exception object.
EXPECTED OUTPUT
Note: Error messages might differ from language to language and the file path as well.
Assignment 6 – Asserts and Try/Catch.
(Here the two assert statements should create popup windows informing the user the string is null or empty and the integer should be greater than 0. Choosing to ignore the assertions should allow the program to continue.)
ArrayOutOfBounds error occurred
Index was outside the bounds of the array.
FileDoesNotExist error occurred
Could not find file
‘C: NoFileNamedThis.txt’
DivideByZero error occurred
Divide By Zero
We offer the bestcustom writing paper services. We have done this question before, we can also do it for you.
Why Choose Us
- 100% non-plagiarized Papers
- 24/7 /365 Service Available
- Affordable Prices
- Any Paper, Urgency, and Subject
- Will complete your papers in 6 hours
- On-time Delivery
- Money-back and Privacy guarantees
- Unlimited Amendments upon request
- Satisfaction guarantee
How it Works
- Click on the “Place Order” tab at the top menu or “Order Now” icon at the bottom and a new page will appear with an order form to be filled.
- Fill in your paper’s requirements in the "PAPER DETAILS" section.
- Fill in your paper’s academic level, deadline, and the required number of pages from the drop-down menus.
- Click “CREATE ACCOUNT & SIGN IN” to enter your registration details and get an account with us for record-keeping and then, click on “PROCEED TO CHECKOUT” at the bottom of the page.
- From there, the payment sections will show, follow the guided payment process and your order will be available for our writing team to work on it.