0
RuntimeError
So I decided to run a raise line without an exception, and it returned a RuntimeError, which I have no idea what that is or means. Here’s the code: https://sololearn.com/compiler-playground/c9G4pKvkkgL0/?ref=app Are there other ways to cause this exception?
8 Réponses
0
New Game ,
Ah. If the code is only the word raise, as Lothar said, you have to specify which error you want to raise.
But if you use it with try and except, it will re-raise whatever error got caught by the except.
try
pass # whatever code
except # catches every exception
pass # whatever code
raise # knows which error to re-raise
Here's another python.org link about exceptions in addition to sandra's. This one's from the tutorial area.
https://docs.python.org/3/tutorial/errors.html#errors-and-exceptions
(Syntax errors aren't exceptions.)
+ 6
New Game ,
if we use the *raise* keyword, we have to say *what type of exception* we want to raise. as sandra already mentioned, the tutorial is a good source to learn from.
may be this sample can help you also:
https://code.sololearn.com/cN33CcVh09sP/?ref=app
+ 3
I think it makes sence that you read the documentation for exceptions:
https://docs.python.org/3/library/exceptions.html
+ 2
New Game ,
I can't read your code on the app but here's what I learned about raise.
try:
pass
except ValueError:
pass
except IndexError:
pass
except:
raise
Normally, you should always use except with a specific exception, such as ValueError, and you should add a separate clause for each error that the code in the try block might automatically raise, such as IndexError, etc.
The separate except clauses allow you to handle each error type appropriately, such as printing a usage string for the user, such as, "Usage: Enter a positive integer."
However, when you're first writing your code, you might not be aware of all the different errors that your try block might automatically raise.
In that case, you can add an except clause with no specified error, and put raise inside it. That will catch any other error that gets raised and re-raise it so it gets printed in the console when you're testing.
Then you can add an except clause for that specific error and continue testing.
+ 2
Got it
+ 1
Rain The only thing in the code is the word raise
0
Well....what are you raising?
0
According to the website from sandra, it’s raised when it doesn’t fall into any of the other categories.