Секція 1. Розділ 4
single
Challenge: Add try/catch to Prevent Crashes
Свайпніть щоб показати меню
Завдання
Swipe to start coding
Add exception handling to prevent the script from crashing when file operations fail. Use a try/catch block in the appropriate place to handle any exceptions thrown by the readFileContents function.
- Wrap the call to
readFileContentsin atry/catchblock. - If
readFileContentssucceeds, assign its return value to a variable and create a message that includes the file contents. - If an exception is caught, create an error message that includes the exception's message.
- Ensure the appropriate message is displayed based on whether an exception occurred.
Рішення
Все було зрозуміло?
Дякуємо за ваш відгук!
Секція 1. Розділ 4
single
Запитати АІ
Запитати АІ
Запитайте про що завгодно або спробуйте одне із запропонованих запитань, щоб почати наш чат