Question: Exception Handling As a test engineer, you are responsible for finding and handling exceptions in the code. Today, your surpervisor gives you a task to

Exception Handling
As a test engineer, you are responsible for finding and handling exceptions in the code. Today, your surpervisor gives you a task to catch the exception in a function. He says that the function is strictly confidential and you do not have the access to the source code. You job is to call the function with different inputs and catch the exception if it occurs.
The function is called black_box and it takes one argument command. The command can be an integer range from 0-9. The function returns nothing if it run successfully. If the function fails, it raises an exception. You need to create a list exception_report to collect all the running results with command from 0-9. The result should be a string with the following format:
If the function raises an ValueError exception, the result should be "Value Error"
If the function raises an TypeError exception, the result should be "Type Error"
If the function raises an ZeroDivisionError exception, the result should be "ZeroDivision Error"
If the function raises an IndexError exception, the result should be "Index Error"
If the function raises an other exception, the result should be "Abnormal Error"
If the function runs successfully, the result should be "Success"
Here are the example of the expected results:
black_box(0) # raises IndexError which should be added to the list exception_report
The setup code gives the following variables:
NameTypeDescriptionblack_boxfunctionfunction that you need to test
Your code snippet should define the following variables:
NameTypeDescriptionexception_reportlistlist that collects the exception messages

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