Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

Clarification regarding a statement on exceptions

My textbook says :

"In Python, exceptions are errors that get triggered automatically. "

What does it mean? I had thought about this statement for sometime but unable to understand it.

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

(P.S. I am a beginner in the computer field . Please give a understandable answer for me)

>Solution :

"In Python, exceptions are errors that get triggered automatically. "

That’s true, an even more correct definition would be the following.

An exception is an event, which occurs during the execution of a program that disrupts the normal flow of the program’s instructions.

You should imagine your interpreter (I guess you’re using CPython) executing line after line until an event happens.

That event can be an error, that is passed to your script as an Exception (or sublcass) object.


"[…] that get triggered automatically"

That’s not completely true, you can throw (or better saying raise) an exception manually.

raise Exception("Error occurred!")
Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading