How to raise exception in Python

2 Answers

0 votes
def f(s):
    raise Exception(s + " : raise Exception")

f("python")


'''
run:

Traceback (most recent call last):
  File ".../test.py", line 4, in <module>
    f("python")
  File ".../test.py", line 2, in f
    raise Exception(s + " : raise Exception")
Exception: python : raise Exception

'''

 



answered Sep 11, 2018 by avibootz
0 votes
x = 243
if x > 20:
    raise Exception('x > 20'.format(x))

 
   
'''
run:
   
Traceback (most recent call last):
  File "main.py", line 3, in <module>
    raise Exception('x > 20'.format(x))
Exception: x > 20
          
'''

 



answered May 17, 2020 by avibootz

Related questions

2 answers 275 views
1 answer 288 views
2 answers 222 views
1 answer 304 views
3 answers 361 views
361 views asked Apr 27, 2021 by avibootz
2 answers 276 views
276 views asked Apr 27, 2021 by avibootz
...