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

Published: 30 April 2021
on channel: Digital Academy
1,138
18

🎓 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:
○ Data Types in Python -    • DATA TYPES in Python (Numbers, Strings, Li...  
○ Operators in Python -    • OPERATORS in Python (Arithmetic, Assignmen...  
○ IF Statements in Python -    • CONDITIONAL Statements in Python (IF, ELIF...  
○ FOR Loops in Python -    • FOR Loop in Python (Syntax, Break, Continu...  

📖 Blog: http://digital.academy.free.fr/blog

📖 [FULL Course] HOW TO Learn Python? Python Tutorial for Beginners:    • 🐍 Python 101: Learn Python Basics for Abso...  

📖 [PLAYLIST] Complete Python Development Course for Beginners: http://digital.academy.free.fr/playli...

🧑‍🎓 [COURSE] http://digital.academy.free.fr/courses

📘 [BOOK] Python for Absolute Beginners: https://amzn.to/3NvyOWV

🛒 Shopping and Discounts: http://digital.academy.free.fr/store

💌 Weekly Newsletter for Developers: https://www.getrevue.co/profile/digit...

#Python #Tutorial #Beginners #Shorts

***

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

***

♡ FOLLOW US ♡
✧ http://digital.academy.free.fr/
✧   / digitalacademyy  
✧   / digitalacademyfr  
✧   / digital_academy_fr  
✧    / digitalacademyonline  

♡ SUPPORT US ♡
✧ http://digital.academy.free.fr/join
✧ http://digital.academy.free.fr/store
✧ http://digital.academy.free.fr/donate
✧ http://digital.academy.free.fr/subscribe
✧   / digital_academy  
✧ https://www.buymeacoffee.com/digital_...

***


On this page of the site you can watch the video online How to RAISE an Exception in Python? (Traceback in Python) - Python Tutorial for Beginners with a duration of hours minute second in good quality, which was uploaded by the user Digital Academy 30 April 2021, share the link with friends and acquaintances, this video has already been watched 1,138 times on youtube and it was liked by 18 viewers. Enjoy your viewing!