+ 2
Hi every one i would like to ask question what is difference between try except statement and raise statement?
THX
6 odpowiedzi
+ 7
The raise statement is not used for catching exceptions. It actually causes an exception, deliberately.
Suppose you have a function that reads a sensor on an engine. If that sensor starts sending data that is outside the expected range, that is when you would want to raise an exception so that emergency measures can be taken.
Somewhere else in the program in the hierarchy of calls to that function, a try/except would catch the exception and jump to the except: portion of the code and handle the emergency.
+ 5
One of them raises an exception. The other detects when an exception occurs in a given suite of code. Can you guess which one does which functionality?
+ 5
Yusof yes, your summary shows a good understanding of the statements.
+ 2
@Brain
Do you mean raise statement only catches error that may happen while try except handle the error?
THX again
+ 2
THX @Brain
now I understand
raise: It was made for making a deliberately exception if there is condition I have put as programmer is not satisfied that leads error message at the top of it traceback
while try except : for unexpected error and handle it also.
Am I right?
+ 1
Thanks Brian for your kindness and your help.