Notice: This page requires JavaScript to function properly.
Please enable JavaScript in your browser settings or update your browser.
Challenge: Catch an Error | Handling Structure
Error Handling in Python
course content

Зміст курсу

Error Handling in Python

Error Handling in Python

1. Handling Structure
2. Exception Usage

Challenge: Catch an Error

Now, let's handle the error for the first time.

You should handle this error:

123
from math import sqrt sqrt(-4) # ValueError
copy

Since finding the square root of a negative number is not possible (according to mathematical concepts), performing this operation in Python is not feasible. The interpreter takes this into account and raises a ValueError with the following message: math domain error.

Завдання

Now, you need to complete the following points:

  1. Define the code block where an error is expected.
  2. Catch this error and print the following string:
    "The ValueError was raised!"

Завдання

Now, you need to complete the following points:

  1. Define the code block where an error is expected.
  2. Catch this error and print the following string:
    "The ValueError was raised!"

Перейдіть на комп'ютер для реальної практикиПродовжуйте з того місця, де ви зупинились, використовуючи один з наведених нижче варіантів

Все було зрозуміло?

Секція 1. Розділ 3
toggle bottom row

Challenge: Catch an Error

Now, let's handle the error for the first time.

You should handle this error:

123
from math import sqrt sqrt(-4) # ValueError
copy

Since finding the square root of a negative number is not possible (according to mathematical concepts), performing this operation in Python is not feasible. The interpreter takes this into account and raises a ValueError with the following message: math domain error.

Завдання

Now, you need to complete the following points:

  1. Define the code block where an error is expected.
  2. Catch this error and print the following string:
    "The ValueError was raised!"

Завдання

Now, you need to complete the following points:

  1. Define the code block where an error is expected.
  2. Catch this error and print the following string:
    "The ValueError was raised!"

Перейдіть на комп'ютер для реальної практикиПродовжуйте з того місця, де ви зупинились, використовуючи один з наведених нижче варіантів

Все було зрозуміло?

Секція 1. Розділ 3
toggle bottom row

Challenge: Catch an Error

Now, let's handle the error for the first time.

You should handle this error:

123
from math import sqrt sqrt(-4) # ValueError
copy

Since finding the square root of a negative number is not possible (according to mathematical concepts), performing this operation in Python is not feasible. The interpreter takes this into account and raises a ValueError with the following message: math domain error.

Завдання

Now, you need to complete the following points:

  1. Define the code block where an error is expected.
  2. Catch this error and print the following string:
    "The ValueError was raised!"

Завдання

Now, you need to complete the following points:

  1. Define the code block where an error is expected.
  2. Catch this error and print the following string:
    "The ValueError was raised!"

Перейдіть на комп'ютер для реальної практикиПродовжуйте з того місця, де ви зупинились, використовуючи один з наведених нижче варіантів

Все було зрозуміло?

Now, let's handle the error for the first time.

You should handle this error:

123
from math import sqrt sqrt(-4) # ValueError
copy

Since finding the square root of a negative number is not possible (according to mathematical concepts), performing this operation in Python is not feasible. The interpreter takes this into account and raises a ValueError with the following message: math domain error.

Завдання

Now, you need to complete the following points:

  1. Define the code block where an error is expected.
  2. Catch this error and print the following string:
    "The ValueError was raised!"

Перейдіть на комп'ютер для реальної практикиПродовжуйте з того місця, де ви зупинились, використовуючи один з наведених нижче варіантів
Секція 1. Розділ 3
Перейдіть на комп'ютер для реальної практикиПродовжуйте з того місця, де ви зупинились, використовуючи один з наведених нижче варіантів
We're sorry to hear that something went wrong. What happened?
some-alt