2. Raising an Exception¶

2.1. Catching the Exception¶

2.2. Handling Exceptions¶
21
from browser import window, prompt, alert
def save_data():
try:
destination = prompt("Enter Destination")
if not destination:
raise ValueError("Destination cannot be empty")
window.sessionStorage["Destination"] = destination
description= prompt("Enter Description")
if not description:
raise ValueError("Description cannot be empty")
window.sessionStorage["Description"] = description
speech= prompt("Enter Speech")
if not speech:
raise ValueError("Speech cannot be empty")
window.sessionStorage["Speech"] = speech
except Exception as exception:
alert(f'Error: {exception}')
save_data()
Activity: 2.2.1 ActiveCode (ac_l54_2a_en)
Note: to test the exception you will need to change the properties of the file

You have attempted 1 of 2 activities on this page