What is raising exceptions used for? | Sololearn: Learn to code for FREE!
Nouvelle formation ! Tous les codeurs devraient apprendre l'IA générative !
Essayez une leçon gratuite
+ 1

What is raising exceptions used for?

Why do you raise and exception if they are already displayed by a try/except statement?

20th Apr 2019, 10:24 PM
commapy - avatar
1 Réponse
+ 5
You want a program to abort if something bad happens, instead of running on and secretly do damage, because data is corrupted or something. So you can control it, for example by raising an exception when the caller of a function gives bad arguments. Program aborts, you give out an error message, the programmer using your function will know what to do about it. If they foresee it, they can use exception handling and prepare a procedure for that case.
20th Apr 2019, 11:11 PM
HonFu - avatar