Module (71%)
Section (71%)

To catch the cause of the RocketNotReadyError exception, you should access the __cause__ attribute of the RocketNotReadyError object.

Run the code in the right pane and examine the output.

This time the report is handled in a safe way, and you can be sure that you’re doing a good job.

Final check procedure The captain's name is John The pilot's name is Mary The mechanic's name is Mike General exception: "Crew is incomplete", caused by "list index out of range"

output


Code

class RocketNotReadyError(Exception):
pass


def personnel_check():
try:
print("\tThe captain's name is", crew[0])
print("\tThe pilot's name is", crew[1])
print("\tThe mechanic's name is", crew[2])
print("\tThe navigator's name is", crew[3])
except IndexError as e:
raise RocketNotReadyError('Crew is incomplete') from e

crew = ['John', 'Mary', 'Mike']
print('Final check procedure')

try:
personnel_check()
except RocketNotReadyError as f:
print('General exception: "{}", caused by "{}"'.format(f, f.__cause__))
{{ dockerServerErrorMsg }} ×
{{ errorMsg }} ×
{{ successMsg }} ×