+ 1

What happens if you use a Raise statment outside an Exception block?

11th Apr 2016, 10:03 PM
md123
md123 - avatar
3 Respuestas
+ 1
It should work good I guess but you should give it a condition otherwise your program will never work. Example: [...] spam = float(input("Enter a positive number")) if var <= 0: raise ValueError [...]
2nd May 2016, 4:59 AM
Javier Vazquez
Javier Vazquez - avatar
+ 1
The exception is simply raised. The point of raising exceptions though is to catch them so you can handle them for specific cases. Thus there's basically no point in raising an exception if not in a block of code, in whatever kind of block for that matter. That being said, raising exceptions is often used as placeholders on some methods on classes where those are supposed to be subclassed. So yes, use them inside of blocks of code.
29th Jun 2016, 9:36 PM
Edgar Garrido
Edgar Garrido - avatar
0
It works the same way as if an error (raising an exception automatically) happens outside of try ... except block. The execution of your code will stop, message about the exception will be printed and the program will quit ... the same way as in the first example of "Raising exceptions".
15th Jun 2016, 8:07 AM
Václav Brožík
Václav Brožík - avatar