How can I raise an exception in Python so that it can later be caught via an except block?

0 votes
How can I raise an exception in Python so that it can later be caught via an except block?
May 29 in Python by Pallavi
17 views

1 answer to this question.

Your answer

Your name to display (optional):
Privacy: Your email address will only be used for sending these notifications.
0 votes

It's pretty simple to raise a query 

raise ValueError('An Ugly exception')

But don't raise genereic exception.

answered May 29 by Umesh

Related Questions In Python

+2 votes
3 answers

How can I play an audio file in the background using Python?

down voteacceptedFor windows: you could use  winsound.SND_ASYNC to play them ...READ MORE

answered Apr 3, 2018 in Python by charlie_brown
• 7,710 points
1,070 views
0 votes
1 answer

How can I find out the index of an element from row and column in Python?

You probably want to use np.ravel_multi_index: [code] import numpy ...READ MORE

answered Apr 16, 2018 in Python by charlie_brown
• 7,710 points
51 views
0 votes
1 answer

How can I print an Error in Python?

For Python 2.6 and later and Python ...READ MORE

answered Oct 12, 2018 in Python by ariaholic
• 7,320 points
24 views
0 votes
0 answers

how can i contribute to an existing open source project in python?

is there a different platform for this ...READ MORE

May 8 in Python by Waseem
• 2,710 points
6 views
0 votes
1 answer

how can i count the items in a list?

suppose you have a list a = [0,1,2,3,4,5,6,7,8,9,10] now ...READ MORE

answered May 2 in Python by Mohammad
• 1,400 points
56 views
+4 votes
6 answers
0 votes
1 answer

How can I turn an input date into a readable string in Python?

The datetime class has a method strftime. strftime() ...READ MORE

answered Dec 11, 2018 in Python by ariaholic
• 7,320 points
26 views
0 votes
1 answer

How can I represent an Enum in Python?

Here is one implementation: class Enum(set): ...READ MORE

answered Dec 11, 2018 in Python by ariaholic
• 7,320 points
36 views

© 2018 Brain4ce Education Solutions Pvt. Ltd. All rights Reserved.
"PMP®","PMI®", "PMI-ACP®" and "PMBOK®" are registered marks of the Project Management Institute, Inc. MongoDB®, Mongo and the leaf logo are the registered trademarks of MongoDB, Inc.