An_Elephant
An_Elephant

Reputation: 131

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.

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

Upvotes: 0

Views: 37

Answers (1)

FLAK-ZOSO
FLAK-ZOSO

Reputation: 4137

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

Upvotes: 1

Related Questions