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

Contenu du cours

Error Handling in Python

Error Handling in Python

1. Handling Structure
2. Exception Usage

book
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.

Tâche

Swipe to start coding

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!"

Solution

Switch to desktopPassez à un bureau pour une pratique réelleContinuez d'où vous êtes en utilisant l'une des options ci-dessous
Tout était clair ?

Comment pouvons-nous l'améliorer ?

Merci pour vos commentaires !

Section 1. Chapitre 3
toggle bottom row

book
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.

Tâche

Swipe to start coding

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!"

Solution

Switch to desktopPassez à un bureau pour une pratique réelleContinuez d'où vous êtes en utilisant l'une des options ci-dessous
Tout était clair ?

Comment pouvons-nous l'améliorer ?

Merci pour vos commentaires !

Section 1. Chapitre 3
Switch to desktopPassez à un bureau pour une pratique réelleContinuez d'où vous êtes en utilisant l'une des options ci-dessous
Nous sommes désolés de vous informer que quelque chose s'est mal passé. Qu'est-il arrivé ?
some-alt