Home > front end >  Clarification regarding a statement on exceptions
Clarification regarding a statement on exceptions

Time:06-10

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.

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

CodePudding user response:

"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!")
  • Related