Welcome to collectivesolver - Programming & Software Q&A with code examples. A website with trusted programming answers. All programs are tested and work.

Contact: aviboots(AT)netvision.net.il

Prodentim Probiotics Specially Designed For The Health Of Your Teeth And Gums

Instant Grammar Checker - Correct all grammar errors and enhance your writing

Teach Your Child To Read

Powerful WordPress hosting for WordPress professionals

Disclosure: My content contains affiliate links.

31,128 questions

40,777 answers

573 users

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 73 views
1 answer 111 views
2 answers 37 views
1 answer 27 views
...