+ 2

What is the use of raising exception in python or program ?

18th Jul 2019, 9:40 AM
Abhi
Abhi - avatar
3 Answers
+ 3
To give the programmer a clear signal of what went wrong, and to stop execution of the program, so that nothing happens that shouldn't. Imagine you write a set of functions that other people will import and use in their code. They can't (or don't want to) read your source code, but when something goes wrong, they want to know what and why. Like when you try to do... '5'/2 ... Python will tell you: 'You can't divide a string by an int.' It's convenient, right? And you can give the same convenience to the users of your code. Who might be yourself, actually, because when you write a very large program, you'll forget, how exactly you have written some function, because it was weeks ago.
18th Jul 2019, 10:22 AM
HonFu
HonFu - avatar
+ 2
Thanks
18th Jul 2019, 10:51 AM
Abhi
Abhi - avatar
+ 1
has a lot of advantages: 1- to make your code more understandable by others 2- to get certain values from users e. g: if your app need number and user entered string ...etc you've to check them online
29th Jul 2019, 2:48 PM
Abdul Shakoor Mousa
Abdul Shakoor Mousa - avatar