Re: Catch exception with message?

2016-06-04 Thread Lawrence D’Oliveiro
On Sunday, June 5, 2016 at 4:44:17 AM UTC+12, Peter Pearson wrote: > ... are you aware that "except Exception" is generally not what you want to > do ... Agree. Always make your “except”-matching as specific as possible. -- https://mail.python.org/mailman/listinfo/python-list

Re: Catch exception with message?

2016-06-04 Thread Peter Pearson
On Sat, 4 Jun 2016 04:44:30 +0530, Piyush Verma <114piy...@gmail.com> wrote: > Generally we catch exception using > except Exception as e: > > But sometimes, we see same type of exception is present with different > message.Is there a way to capture same exception with message > filtering? Please

Re: Catch exception with message?

2016-06-04 Thread Piyush Verma
Below is exception type and it is user defined exception. I do not see error number in exception stack. What other option we can use as filter in below exception apart from message? UserDefinedException: User defined message: {} #012 File "/opt/cio/lib/python2.7/site-packages/manager.py", line

Re: Catch exception with message?

2016-06-03 Thread Steven D'Aprano
On Sat, 4 Jun 2016 09:14 am, Piyush Verma wrote: > Generally we catch exception using > except Exception as e: > > But sometimes, we see same type of exception is present with different > message. That suggests that whoever wrote the code doesn't know what they're doing. Intentionally giving

Re: Catch exception with message?

2016-06-03 Thread cs
On 04Jun2016 04:44, Piyush Verma <114piy...@gmail.com> wrote: Generally we catch exception using except Exception as e: But sometimes, we see same type of exception is present with different message.Is there a way to capture same exception with message filtering? Please help me to do this.

Re: Catch exception with message?

2016-06-03 Thread Ben Finney
Piyush Verma <114piy...@gmail.com> writes: > But sometimes, we see same type of exception is present with different > message.Is there a way to capture same exception with message > filtering? Please help me to do this. That's a nasty code smell. Why would you want your code to behave

Re: Catch exception with message?

2016-06-03 Thread Random832
On Fri, Jun 3, 2016, at 19:14, Piyush Verma wrote: > Generally we catch exception using > except Exception as e: > > But sometimes, we see same type of exception is present with different > message.Is there a way to capture same exception with message > filtering? Please help me to do this. The

Re: Catch exception with message?

2016-06-03 Thread Ian Kelly
try: something except Exception as e: if e.args[0] == message_of_interest: handle_it else: raise On Fri, Jun 3, 2016 at 5:14 PM, Piyush Verma <114piy...@gmail.com> wrote: > Generally we catch exception using > except Exception as e: > > But sometimes, we see same type

Catch exception with message?

2016-06-03 Thread Piyush Verma
Generally we catch exception using except Exception as e: But sometimes, we see same type of exception is present with different message.Is there a way to capture same exception with message filtering? Please help me to do this. Regards, ~Piyush --