How to RAISE an Exception in Python? (Traceback in Python) - Python Tutorial for Beginners

preview_player
Показать описание
🎓 Welcome back to Digital Academy, the Complete Python Development Tutorial for Beginners, which will help you Learn Python from A to Z!

🖥️ How to Raise and Throw an Exception in Python? (Traceback in Python)

In Python programming, exceptions are raised when errors occur at runtime. But, as a Python developer, you can also choose to manually throw an exception, if a condition is met - and at any time. To raise such an exception, use the RAISE reserved keyword.

This statement RAISE in Python can be complemented with a Custom Exception. You can optionally define what kind of error to raise, and pass values to the exception to clarify why that exception was raised. Then, the program comes to a halt and it displays your exception to screen - offering clues about what went wrong and help debugging.

# Raise built-in exception 'NameError'
raise NameError('An exception occured!')

# Output:
# Traceback (most recent call last):
# File "stdin", line 1, in module
# NameError: An exception occured!

Let's play this video, stick around and watch until the end of this video! 👍🏻

- Digital Academy™ 🎓

***

☞ WATCH NEXT:

#Python #Tutorial #Beginners #Shorts

***

♡ Thanks for watching and supporting ♡
Please Subscribe. Hit the notification bell.
Like, Comment and Share.

***

♡ FOLLOW US ♡

♡ SUPPORT US ♡

***
Рекомендации по теме
Комментарии
Автор

Merci pour cette vidéo très instructive prof :-)

PassionsByCath