+ 7
Raise error
Can anyone please explain in detail when and why we need to raise an error ? Thank you sooo much
4 Respostas
+ 8
It comes in handy when you are making your own module or any part of the code which you want to make sure will work, in order not to have to look into it later on. If there are potentially many lines of code which might result in an error, you might want to manually raise them with a special signing, just so you know which part exactly is wrong.
+ 4
There can be occasions were user is asked to give input while executing a code. But the user may choose to give wrong inputs that can corrupt the database. so a programmer needs to include options to raise error or an exception when wrong combination manifests in a program execution due various reasons, including wrong inputs.
+ 2
Sorry <^> washika D <^> - you were technically right about that - i did't saw at the moment the next few lessons about the raise/try/except functionality. My apologies. I hope all our answers helps C.R.Devila understand the exception issue. Good day to you all.
0
<^> washika D <^> - i don't see how this is helpfull for C.R.Devila. I wil be glad tough to find out more about your first statement - maybe you wrote how you can "raise"without "try/except" - sorry, i don't see it. The next two answers are very good, each of them looking from one perspective or another. My opinion is that, if you look from a mathematical point of view, in your program a variable can take from time to time, even with all your constraints put right, values wich are incompatible with a portion of your code or all the rest of it. This is taking place even with good inputs or bad ones. It's better for you, when you can forsee that possibility to signal that the values inputed or outputed are indeed wrong - for a reason or another. Example: say you calculate in a module the velocity of an object and you're answer is a negative number. Instead of going on and use that value into another module(s) you can "raise" an Error and try to find out what's going on.