How to get insight in the relations between tracebacks of exceptions in an exception-chain

2024-04-04 Thread Klaas van Schelven via Python-list
appening that this SO question is about. regards, Klaas Previously asked here: https://stackoverflow.com/questions/78270044/how-to-get-insight-in-the-relations-between-tracebacks-of-exceptions-in-an-excep -- https://mail.python.org/mailman/listinfo/python-list

Re: on the importance of exceptions

2022-09-06 Thread Meredith Montgomery
Meredith Montgomery writes: > I'm trying to show people that exceptions are a very nice thing to have > when it comes to detecting when something went awry somewhere. I'd like > a real-world case, though. Here's my contribution. I want to handle all errors in main()

on the importance of exceptions

2022-09-06 Thread Meredith Montgomery
I'm trying to show people that exceptions are a very nice thing to have when it comes to detecting when something went awry somewhere. I'd like a real-world case, though. Here's what I'm sort of coming up with --- given my limited experience and imagination. Below, you hav

Re: Best practice for handling exceptions raised at lower levels?

2021-02-02 Thread Greg Ewing
On 3/02/21 9:24 am, Dan Stromberg wrote: But how do you know what exceptions could be raised? Mostly I find that it's not really necessary to know precisely which exceptions could be raised. The way I usually deal with exceptions is: 1. If it descends from OSError, I assume it results

Re: Best practice for handling exceptions raised at lower levels?

2021-02-02 Thread Barry Scott
> On 2 Feb 2021, at 20:24, Dan Stromberg wrote: > > > > On Tue, Feb 2, 2021 at 12:00 PM Barry Scott <mailto:ba...@barrys-emacs.org>> wrote: > When I write packages I aim to trap the exceptions from the lower levels > and convert into a package specific exc

Re: Best practice for handling exceptions raised at lower levels?

2021-02-02 Thread Chris Angelico
On Wed, Feb 3, 2021 at 7:26 AM Dan Stromberg wrote: > > On Tue, Feb 2, 2021 at 12:00 PM Barry Scott wrote: > > > When I write packages I aim to trap the exceptions from the lower levels > > and convert into a package specific exceptions or document that a low > > le

Re: Best practice for handling exceptions raised at lower levels?

2021-02-02 Thread Dan Stromberg
On Tue, Feb 2, 2021 at 12:00 PM Barry Scott wrote: > When I write packages I aim to trap the exceptions from the lower levels > and convert into a package specific exceptions or document that a low > level exception can propagate. > But how do you know what exceptions could be rai

Re: Best practice for handling exceptions raised at lower levels?

2021-02-02 Thread Barry Scott
> On 2 Feb 2021, at 00:54, Skip Montanaro wrote: > > I'm curious if there are best practices for handling exceptions raised > by lower level modules and packages. For example, I wrote an > application called polly[1] which constructs a personalized dictionary > from ema

Re: Best practice for handling exceptions raised at lower levels?

2021-02-02 Thread Terry Reedy
On 2/1/2021 7:54 PM, Skip Montanaro wrote: However... Network applications being what they are, hiccups are going to happen. In the time since I swapped in the imapclient package, I've also had to catch exceptions raised by lower level modules/packages I wasn't using directly, discov

Re: Best practice for handling exceptions raised at lower levels?

2021-02-02 Thread Antoon Pardon
sibility of the application author or the package author? This isn't an issue just for network applications with a number of moving parts (socket, ssl, higher level packages, etc). It happens in almost all applications or packages, even if it's just to deal with exceptions raised by

Best practice for handling exceptions raised at lower levels?

2021-02-01 Thread Skip Montanaro
I'm curious if there are best practices for handling exceptions raised by lower level modules and packages. For example, I wrote an application called polly[1] which constructs a personalized dictionary from email messages using IMAP4. That dictionary is then used as input to a password gene

RE: How do you find what exceptions a class can throw?

2020-12-21 Thread Avi Gross via Python-list
can write some code that catches every possible exception then carefully logs all details, and then perhaps quits. If you run your code many times and even cause reasons for it to fail, you may develop some knowledge of some of the exceptions that make it through back to your call and then you

Re: How do you find what exceptions a class can throw?

2020-12-21 Thread Terry Reedy
On 12/21/2020 4:06 AM, Chris Green wrote: Avi Gross wrote: The original question sounded like someone was asking what errors might be thrown for a routine they wrote that used other components that might directly throw exceptions or called yet others, ad nauseum. OP here. The original

Re: How do you find what exceptions a class can throw?

2020-12-21 Thread Grant Edwards
On 2020-12-21, Chris Angelico wrote: > On Mon, Dec 21, 2020 at 1:11 PM Julio Di Egidio wrote: >> > Gathering evidence is indeed part of science, and computer science is >> > indeed mathematics, but alas programmering is just a craft and software >> > engineering often ... isn't. >> >> Programming

Re: How do you find what exceptions a class can throw?

2020-12-21 Thread Chris Angelico
On Tue, Dec 22, 2020 at 12:32 AM Larry Martell wrote: > > On Sun, Dec 20, 2020 at 9:36 PM Chris Angelico wrote: > > > > On Mon, Dec 21, 2020 at 1:11 PM Julio Di Egidio wrote: > > > > Gathering evidence is indeed part of science, and computer science is > > > > indeed mathematics, but alas progra

Re: How do you find what exceptions a class can throw?

2020-12-21 Thread Larry Martell
On Sun, Dec 20, 2020 at 9:36 PM Chris Angelico wrote: > > On Mon, Dec 21, 2020 at 1:11 PM Julio Di Egidio wrote: > > > Gathering evidence is indeed part of science, and computer science is > > > indeed mathematics, but alas programmering is just a craft and software > > > engineering often ... is

Re: How do you find what exceptions a class can throw?

2020-12-21 Thread Chris Green
Avi Gross wrote: > The original question sounded like someone was asking what errors might be > thrown for a routine they wrote that used other components that might > directly throw exceptions or called yet others, ad nauseum. > OP here. The original question was because I wa

Re: How do you find what exceptions a class can throw?

2020-12-20 Thread 2QdxY4RzWzUUiLuE
nd the reasons behind them is amongst the best of Best Practices. That said, either way, it's the same thing. If A calls B, and B calls C, and B claims *not* to handle exceptions X and Y, then A has to track down everything else that might come from C, and we're right back to square on

RE: How do you find what exceptions a class can throw?

2020-12-20 Thread Avi Gross via Python-list
The original question sounded like someone was asking what errors might be thrown for a routine they wrote that used other components that might directly throw exceptions or called yet others, ad nauseum. Some have questioned the purpose. I can well imagine that if such info was available, you

Re: How do you find what exceptions a class can throw?

2020-12-20 Thread Chris Angelico
On Mon, Dec 21, 2020 at 1:11 PM Julio Di Egidio wrote: > > Gathering evidence is indeed part of science, and computer science is > > indeed mathematics, but alas programmering is just a craft and software > > engineering often ... isn't. > > Programming is a *discipline* It's a discipline, a scie

Re: How do you find what exceptions a class can throw?

2020-12-20 Thread Ethan Furman
On 12/20/20 6:06 PM, Julio Di Egidio wrote: You could have taken the chance to pay attention Programming is a *discipline*, while you keep echoing cheap and vile marketing nonsense. I am sure you do, rigour mortis eventually... Mean-spirited and hostile messages are not welcome on this

Re: How do you find what exceptions a class can throw?

2020-12-20 Thread Julio Di Egidio
On Sunday, 20 December 2020 at 23:16:10 UTC+1, cameron...@gmail.com wrote: > On 20Dec2020 20:34, Karsten Hilbert wrote: > >> Trust me: it takes 100x getting anything done plus keep up with your > >> prayers, and it takes 100^100x learning anything solid, as in just forget > >> about it. Indeed,

Re: How do you find what exceptions a class can throw?

2020-12-20 Thread Cameron Simpson
On 20Dec2020 20:34, Karsten Hilbert wrote: >> Trust me: it takes 100x getting anything done plus keep up with your >> prayers, and it takes 100^100x learning anything solid, as in just forget >> about it. Indeed, consider that we are rather going to the formal >> verification of programs, soft

Re: How do you find what exceptions a class can throw?

2020-12-20 Thread 2QdxY4RzWzUUiLuE
On 2020-12-20 at 18:25:40 -, Grant Edwards wrote: > On 2020-12-20, 2qdxy4rzwzuui...@potatochowder.com > <2qdxy4rzwzuui...@potatochowder.com> wrote: > > Chris Green wrote: > > > >>> Ultimately, it is not possible to tell what exceptions > >>

Aw: Re: Re: Re: How do you find what exceptions a class can throw?

2020-12-20 Thread Karsten Hilbert
> Trust me: it takes 100x getting anything done plus keep up with your prayers, > and it takes 100^100x learning anything solid, as in just forget about it. > Indeed, consider that we are rather going to the formal verification of > programs, software, and even hardware... I sincerly wish you

Re: Re: Re: How do you find what exceptions a class can throw?

2020-12-20 Thread Julio Di Egidio
On Sunday, 20 December 2020 at 19:54:08 UTC+1, Karsten Hilbert wrote: > > > So what you are looking for is the form of a potential > > > "timeout exception" (say, exception name) ? > > > > > > Provoke one and have a look. > > > > > > Then catch what you saw. > > > >

Re: How do you find what exceptions a class can throw?

2020-12-20 Thread Grant Edwards
On 2020-12-20, 2qdxy4rzwzuui...@potatochowder.com <2qdxy4rzwzuui...@potatochowder.com> wrote: > Chris Green wrote: > >>> Ultimately, it is not possible to tell what exceptions >>> a call might throw. While it may not be "ultimately possible",

Aw: Re: Re: How do you find what exceptions a class can throw?

2020-12-20 Thread Karsten Hilbert
> > So what you are looking for is the form of a potential > > "timeout exception" (say, exception name) ? > > > > Provoke one and have a look. > > > > Then catch what you saw. > > > > Programmers don't guess... I did not suggest gue

Re: How do you find what exceptions a class can throw?

2020-12-20 Thread Chris Green
Stefan Ram wrote: > Chris Green writes: > >So that, as is always advised, I can catch the specific exception > >being thrown! > > It usually is advisable to be more specific when catching > exceptions. The worst thing to do is surely a bare "except:" &g

Re: Re: How do you find what exceptions a class can throw?

2020-12-20 Thread Julio Di Egidio
On Sunday, 20 December 2020 at 19:35:21 UTC+1, Karsten Hilbert wrote: > > If it's a timeout exception I'm going to delay a little while and then > > try again. The timeout is probably because the server is busy. > > So what you are looking for is the form of a potential > "timeout exception" (s

Aw: Re: How do you find what exceptions a class can throw?

2020-12-20 Thread Karsten Hilbert
> > Remember, you get reporting (a traceback) and program cleanup and exit > > for free. What will catching an exception *add* to the user experience? > > If it's a timeout exception I'm going to delay a little while and then > try again. The timeout is probably because the server is busy. So wh

Re: How do you find what exceptions a class can throw?

2020-12-20 Thread Chris Green
2qdxy4rzwzuui...@potatochowder.com wrote: > On 2020-12-20 at 16:02:53 +, > Regarding "Re: How do you find what exceptions a class can throw?," > Chris Green wrote: > > > Stefan Ram wrote: > > > Chris Green writes: > > > >I am using poplib.

Re: How do you find what exceptions a class can throw?

2020-12-20 Thread Julio Di Egidio
On Sunday, 20 December 2020 at 18:18:26 UTC+1, Chris Green wrote: > If I ignore the exception then the > program just exits, if I want the program to do something useful about > it (like try again) then I have to catch the specific exception as I > don't want to try again with

Re: How do you find what exceptions a class can throw?

2020-12-20 Thread 2QdxY4RzWzUUiLuE
On 2020-12-20 at 16:02:53 +, Regarding "Re: How do you find what exceptions a class can throw?," Chris Green wrote: > Stefan Ram wrote: > > Chris Green writes: > > >I am using poplib.POP3_SSL() and I want to know what exceptions can be > > >thrown

Re: How do you find what exceptions a class can throw?

2020-12-20 Thread Chris Green
Stefan Ram wrote: > Chris Green writes: > >I am using poplib.POP3_SSL() and I want to know what exceptions can be > >thrown when I instantiate it. Presumably it inherits them because > >there's nothing much in the documentation page for poplib.POP3_SSL(). > >

Re: How do you find what exceptions a class can throw?

2020-12-20 Thread dn via Python-list
On 20/12/2020 22:39, Chris Green wrote: I am using poplib.POP3_SSL() and I want to know what exceptions can be thrown when I instantiate it. Presumably it inherits them because there's nothing much in the documentation page for poplib.POP3_SSL(). I specifically want to trap timeout excep

How do you find what exceptions a class can throw?

2020-12-20 Thread Chris Green
I am using poplib.POP3_SSL() and I want to know what exceptions can be thrown when I instantiate it. Presumably it inherits them because there's nothing much in the documentation page for poplib.POP3_SSL(). I specifically want to trap timeout exceptions. (... and, yes, I know I should

Re: Exceptions versus Windows ERRORLEVEL

2020-04-06 Thread Stephen Tucker
Thanks, Eryk - this is very helpful. Stephen. On Mon, Apr 6, 2020 at 6:43 AM Eryk Sun wrote: > On 4/3/20, Stephen Tucker wrote: > > > > Does an exception raised by a Python 3.x program on a Windows machine set > > ERRORLEVEL? > > ERRORLEVEL is an internal state of the CMD shell. It has nothing

Re: Exceptions versus Windows ERRORLEVEL

2020-04-05 Thread Eryk Sun
On 4/3/20, Stephen Tucker wrote: > > Does an exception raised by a Python 3.x program on a Windows machine set > ERRORLEVEL? ERRORLEVEL is an internal state of the CMD shell. It has nothing to do with Python. If Python exits due to an unhandled exception, the process exit code will be 1. If CMD w

Re: Exceptions versus Windows ERRORLEVEL

2020-04-04 Thread Luuk
On 3-4-2020 02:08, Stephen Tucker (Stephen Tucker) wrote: Hi, I have found that raising an exception in a Python 2.7.10 program running under Windows does not set ERRORLEVEL. I realise that Python 2.x is no longer supported. Does an exception raised by a Python 3.x program on a Windows machine

Exceptions versus Windows ERRORLEVEL

2020-04-03 Thread Stephen Tucker
Hi, I have found that raising an exception in a Python 2.7.10 program running under Windows does not set ERRORLEVEL. I realise that Python 2.x is no longer supported. Does an exception raised by a Python 3.x program on a Windows machine set ERRORLEVEL? If not, are there plans for it to do so?

Re: with exceptions?

2018-12-19 Thread Marko Rauhamaa
t recommended to continue to use »finally« in such > cases? I'd advice against such ambiguous use of exceptions. I'd write: try: f = open('file') except WhatEverException as e: print(e) else: with f: try: use(f)

Re: Tracebacks for exceptions in interactively entered code.

2018-05-07 Thread Serhiy Storchaka
07.05.18 22:59, Terry Reedy пише: I intend to improve the IDLE doc section on IDLE-console differences. Don't haste to document it. The behavior of the standard interactive mode can be changed in 3.8. -- https://mail.python.org/mailman/listinfo/python-list

Re: Tracebacks for exceptions in interactively entered code.

2018-05-07 Thread Steven D'Aprano
On Mon, 07 May 2018 15:59:10 -0400, Terry Reedy wrote: > I intend to improve the IDLE doc section on IDLE-console differences. > > The following is from standard interactive mode (PSF CPython 3.7.0a4) on > Windows (Win 10, Command Prompt) > > >>> def f(): > ... return 1/0 > ... > >>> f() >

Tracebacks for exceptions in interactively entered code.

2018-05-07 Thread Terry Reedy
I intend to improve the IDLE doc section on IDLE-console differences. The following is from standard interactive mode (PSF CPython 3.7.0a4) on Windows (Win 10, Command Prompt) >>> def f(): ... return 1/0 ... >>> f() Traceback (most recent call last): File "", line 1, in File "", line

Re: Python doesn't catch exceptions ?

2017-02-01 Thread Ian Kelly
On Wed, Feb 1, 2017 at 8:11 AM, Ivo Bellin Salarin wrote: > This code generates instead the messages: > ``` > ERROR 47.135[bigquery.py.create_table:362] caught exception: HttpError, > defined in server/libs/googleapiclient/errors.pyc. we are in > /Users/nilleb/dev/gae-sample-project/app > ERROR 47

Re: Python doesn't catch exceptions ?

2017-02-01 Thread Peter Otten
Ivo Bellin Salarin wrote: > Hi all, > > I have a curious problem with Python exceptions. > > The following code doesn't catch HttpError: > ``` > from server.libs.googleapiclient.errors import HttpError > [..] > try: > OAuth.backoffExec(request)

Python doesn't catch exceptions ?

2017-02-01 Thread Ivo Bellin Salarin
Hi all, I have a curious problem with Python exceptions. The following code doesn't catch HttpError: ``` from server.libs.googleapiclient.errors import HttpError [..] try: OAuth.backoffExec(request) return True except HttpError as e: return e.resp.status =

The use of sys.exc_info for catching exceptions

2017-02-01 Thread Tiago M. Vieira
Hi, I've came to a problem where I want to keep backwards and forwards compatibility with an exception syntax. And I mean by backwards going further down to Python 2.5. I was pointed to this option from a stack overflow answer[1] that works forward and backwards, I rewrite the solution here: imp

Re: try-except with no exceptions

2016-10-15 Thread Nobody
On Thu, 13 Oct 2016 15:06:25 +0100, Daiyue Weng wrote: > I know that such try-catch usage is generally a bad practice, since it > can't locate the root of the exceptions. > > I am wondering how to correct the code above Either identify the specific exceptions you're e

Re: try-except with no exceptions

2016-10-13 Thread Ben Finney
Daiyue Weng writes: > I am wondering how to correct the code above (what it tries to do is > basically trying one processing block, if not working, running another > block of code in except). Also a warning 'Too broad exception clause' > will be generated. Yes. You need to be *very* clear about

Re: try-except with no exceptions

2016-10-13 Thread Peter Otten
Daiyue Weng wrote: > Hi, I have seen code using try_except with no exceptions, > > from dateutil import parser > > try: > from_date = datetime.datetime.strptime(parameters['from_date'], > '%Y-%m-%d %H:%M:%S.%f') > to_date = datetime.datetime

Re: try-except with no exceptions

2016-10-13 Thread Jussi Piitulainen
Daiyue Weng writes: > Hi, I have seen code using try_except with no exceptions, > > from dateutil import parser > > try: > from_date = datetime.datetime.strptime(parameters['from_date'], > '%Y-%m-%d %H:%M:%S.%f') > to_date = datetime.datetime.st

try-except with no exceptions

2016-10-13 Thread Daiyue Weng
Hi, I have seen code using try_except with no exceptions, from dateutil import parser try: from_date = datetime.datetime.strptime(parameters['from_date'], '%Y-%m-%d %H:%M:%S.%f') to_date = datetime.datetime.strptime(parameters['to_date'], '%Y-%m-%d

Re: Capturing the bad codes that raise UnicodeError exceptions during decoding

2016-08-06 Thread Matt Ruffalo
On 2016-08-04 15:45, Random832 wrote: > On Thu, Aug 4, 2016, at 15:22, Malcolm Greene wrote: >> Hi Chris, >> >> Thanks for your suggestions. I would like to capture the specific bad >> codes *before* they get replaced. So if a line of text has 10 bad codes >> (each one raising UnicodeError), I woul

Re: Capturing the bad codes that raise UnicodeError exceptions during decoding

2016-08-04 Thread Malcolm Greene
Wow!!! A huge thank you to all who replied to this thread! Chris: You gave me some ideas I will apply in the future. MRAB: Thanks for exposing me to the extended attributes of the UnicodeError object (e.start, e.end, e.object). Mike: Cool example! I like how _cleanlines() recursively calls itse

Re: Capturing the bad codes that raise UnicodeError exceptions during decoding

2016-08-04 Thread Michael Selik
On Thu, Aug 4, 2016 at 3:24 PM Malcolm Greene wrote: > Hi Chris, > > Thanks for your suggestions. I would like to capture the specific bad > codes *before* they get replaced. So if a line of text has 10 bad codes > (each one raising UnicodeError), I would like to track each exception's > bad code

Re: Capturing the bad codes that raise UnicodeError exceptions during decoding

2016-08-04 Thread Chris Angelico
On Fri, Aug 5, 2016 at 5:22 AM, Malcolm Greene wrote: > Thanks for your suggestions. I would like to capture the specific bad > codes *before* they get replaced. So if a line of text has 10 bad codes > (each one raising UnicodeError), I would like to track each exception's > bad code but still ret

Re: Capturing the bad codes that raise UnicodeError exceptions during decoding

2016-08-04 Thread Random832
On Thu, Aug 4, 2016, at 15:22, Malcolm Greene wrote: > Hi Chris, > > Thanks for your suggestions. I would like to capture the specific bad > codes *before* they get replaced. So if a line of text has 10 bad codes > (each one raising UnicodeError), I would like to track each exception's > bad code

Re: Capturing the bad codes that raise UnicodeError exceptions during decoding

2016-08-04 Thread MRAB
On 2016-08-04 20:22, Malcolm Greene wrote: Hi Chris, Thanks for your suggestions. I would like to capture the specific bad codes *before* they get replaced. So if a line of text has 10 bad codes (each one raising UnicodeError), I would like to track each exception's bad code but still return a v

Re: Capturing the bad codes that raise UnicodeError exceptions during decoding

2016-08-04 Thread Malcolm Greene
Hi Chris, Thanks for your suggestions. I would like to capture the specific bad codes *before* they get replaced. So if a line of text has 10 bad codes (each one raising UnicodeError), I would like to track each exception's bad code but still return a valid decode line when finished. My goal is

Re: Capturing the bad codes that raise UnicodeError exceptions during decoding

2016-08-04 Thread Chris Angelico
On Fri, Aug 5, 2016 at 4:47 AM, Malcolm Greene wrote: > I'm processing a lot of dirty CSV files and would like to track the bad > codes that are raising UnicodeErrors. I'm struggling how to figure out > what the exact codes are so I can track them, them remove them, and then > repeat the decoding

Capturing the bad codes that raise UnicodeError exceptions during decoding

2016-08-04 Thread Malcolm Greene
I'm processing a lot of dirty CSV files and would like to track the bad codes that are raising UnicodeErrors. I'm struggling how to figure out what the exact codes are so I can track them, them remove them, and then repeat the decoding process for the current line until the line has been fully deco

Re: How asyncio works? and event loop vs exceptions

2016-07-25 Thread Marco Sulla via Python-list
On 23 July 2016 at 16:06, Ian Kelly wrote: > On Fri, Jul 22, 2016 at 6:27 PM, Marco S. via Python-list > wrote: >> Furthermore I have a question about exceptions in asyncio. If I >> understand well how it works, tasks exceptions can be caught only if >> you wait for tas

Re: How asyncio works? and event loop vs exceptions

2016-07-23 Thread Ian Kelly
On Fri, Jul 22, 2016 at 6:27 PM, Marco S. via Python-list wrote: > Furthermore I have a question about exceptions in asyncio. If I > understand well how it works, tasks exceptions can be caught only if > you wait for task completion, with yield from, await or > loop.run_until_com

Re: How asyncio works? and event loop vs exceptions

2016-07-23 Thread Terry Reedy
to an asyncio program before loop.run_forever and the loop will drive a tkinter gui. A day ago, I experimentally patched IDLE to run off of an asyncio loop instead of the tk loop. Everything I tried worked. See https://bugs.python.org/issue27546. Furthermore I have a question about except

How asyncio works? and event loop vs exceptions

2016-07-22 Thread Marco S. via Python-list
t's single threaded (if you don't use loop.run_in_executor()). I just tried to imagine that it should act as a cpu scheduler. Is this true? If so, how and when asyncio decide to switch to another task? Furthermore I have a question about exceptions in asyncio. If I understand well how it works,

Re: Handling exceptions with Py2 and Py3

2016-05-27 Thread Ben Finney
Random832 writes: > On Fri, May 27, 2016, at 09:18, Ben Finney wrote: > > try: > > short_routine() > > except ConnectionRefusedError as exc: > > handle_connection_refused(exc) > > except OSError as exc: > > if exc.errno == errno.ECONNREFUSED: > > ha

Re: Handling exceptions with Py2 and Py3

2016-05-27 Thread Random832
On Fri, May 27, 2016, at 09:18, Ben Finney wrote: > try: > short_routine() > except ConnectionRefusedError as exc: > handle_connection_refused(exc) > except OSError as exc: > if exc.errno == errno.ECONNREFUSED: > handle_connection_refused(exc) But Co

Re: Handling exceptions with Py2 and Py3

2016-05-27 Thread Pavlos Parissis
On 27/05/2016 02:51 μμ, Steven D'Aprano wrote: > On Fri, 27 May 2016 10:24 pm, Pavlos Parissis wrote: > >> Hi, >> >> So, we have ConnectionRefusedError in Python3 but not in Python2. >> Six module doesn't provide a wrapper about this. >> >> What is most efficient way to handle this situation in a

Re: Handling exceptions with Py2 and Py3

2016-05-27 Thread Ben Finney
Pavlos Parissis writes: > So, we have ConnectionRefusedError in Python3 but not in Python2. > Six module doesn't provide a wrapper about this. There are many new exception types in Python 3 that inherit from OSError. They are designed to be more precise than disambiguuating the many reasons an O

Re: Handling exceptions with Py2 and Py3

2016-05-27 Thread Steven D'Aprano
On Fri, 27 May 2016 10:24 pm, Pavlos Parissis wrote: > Hi, > > So, we have ConnectionRefusedError in Python3 but not in Python2. > Six module doesn't provide a wrapper about this. > > What is most efficient way to handle this situation in a try-catch block? Um, could you give us a hint as to co

Handling exceptions with Py2 and Py3

2016-05-27 Thread Pavlos Parissis
Hi, So, we have ConnectionRefusedError in Python3 but not in Python2. Six module doesn't provide a wrapper about this. What is most efficient way to handle this situation in a try-catch block? Cheers, Pavlos signature.asc Description: OpenPGP digital signature -- https://mail.python.org/mail

Re: How to handle exceptions properly in a pythonic way?

2015-11-09 Thread zljubisic
a picture. Thanks. I have to rethink now about two approaches. One would be as you have suggested in this mail - raising ContentNotFoundError, and another one would be not to mask root exceptions and deal with them instead of ContentNotFoundError. You have clarified to me the concept. Thanks. Reg

Re: How to handle exceptions properly in a pythonic way?

2015-11-09 Thread zljubisic
Hi, You are right. I am trying to address a few questions at the same time. As English is not my first language, I can only say that you have addressed them very well. Thanks. 1. Where to put the try/except block, inside or outside the function 2. How to deal with un-anticipated exceptions 3

Re: How to handle exceptions properly in a pythonic way?

2015-11-04 Thread tian . su . yale
Hi, If I may, I feel you are tying to address a few questions at the same time, although they are related 1. Where to put the try/except block, inside or outside the function 2. How to deal with un-anticipated exceptions 3. How to keep record My personal feelings are: 1. Kind of prefer try/except

Re: How to handle exceptions properly in a pythonic way?

2015-11-04 Thread tian . su . yale
ign: with the try/except block inside or outside the function 2. Exception Handling: What to do with new un-anticipated exceptions 3. How to record the exception for reference: logging or special value My feeling is: 1. Personally prefer to put try/except block outside the function, to keep the code

Re: How to handle exceptions properly in a pythonic way?

2015-11-04 Thread Chris Angelico
s of a type that you expect - the server didn't respond, or the OS threw back a failure, or whatever. (You'd decide what set of exceptions this represents.) In this case, you get a single exception that wraps that up and summarizes the problem as "Content Not Found"

Re: How to handle exceptions properly in a pythonic way?

2015-11-04 Thread zljubisic
> Which would you prefer? So if I am just checking for the ConnectionError in get_html and a new exception arises, I will have traceback to the get_html function showing that unhandled exception has happened. Now I have to put additional exception block for managing the new exception in the get

Re: How to handle exceptions properly in a pythonic way?

2015-11-04 Thread zljubisic
On Monday, 2 November 2015 21:59:45 UTC+1, Ian wrote: > I'm having a hard time understanding what question you're asking. :) I am really having a hard time to explain the problem as English is not my first language. > You > have a lot of discussion about where to handle e

Re: How to handle exceptions properly in a pythonic way?

2015-11-04 Thread Chris Angelico
On Thu, Nov 5, 2015 at 2:41 PM, wrote: > Raising an exception forces me to put every call of the get_html function in > try/except block. > If I am returning a special value, than I can call get_html and then test the > value. > > I am not sure which approach is better. Raising an exception me

Re: How to handle exceptions properly in a pythonic way?

2015-11-04 Thread zljubisic
> The best way is probably to do nothing at all, and let the caller handle > any exceptions. In that case every call of the get_html function has to be in the try/except block with many exceptions. Sometimes, it is enough just to know whether I managed to get the html or not. In that c

Re: How to handle exceptions properly in a pythonic way?

2015-11-02 Thread Ian Kelly
On Mon, Nov 2, 2015 at 12:24 PM, wrote: > I have read some articles that returning None is not a good approach, so I am > confused. > > How to handle exceptions properly in a pythonic way? I'm having a hard time understanding what question you're asking. You have a l

Re: How to handle exceptions properly in a pythonic way?

2015-11-02 Thread John Gordon
In <4b303213-62e2-42d4-b2f6-4fc1f6025...@googlegroups.com> zljubi...@gmail.com writes: > Let's say that I have the following simple function: > def get_html(url): > wpage = requests.get(url) > > return wpage.text > How to handle exceptions properly th

How to handle exceptions properly in a pythonic way?

2015-11-02 Thread zljubisic
Let's say that I have the following simple function: def get_html(url): wpage = requests.get(url) return wpage.text How to handle exceptions properly that can arise during execution of the requests.get(url)? If I call this function with try: html = get_html('w

Catching exceptions from logging socket handler

2015-09-18 Thread Larry Martell
I have a socket logging handler and I want to be able to catch exceptions from it. Specifically, I want to know if the remote side has gone away so I can close the socket and reopen it when the remote side come back. What happens now is that I get Broken pipe and BAD_WRITE_RETRY exceptions, but

Re: Catching exceptions with multi-processing

2015-06-21 Thread Paul Rubin
Fabien writes: > I am developing a tool which works on individual entities (glaciers) > and do a lot of operations on them. There are many tasks to do, one > after each other, and each task follows the same interface: ... If most of the resources will be spent on computation and the communication

Re: Catching exceptions with multi-processing

2015-06-20 Thread Fabien
On 06/20/2015 05:14 AM, Cameron Simpson wrote: I would keep your core logic Pythonic, raise exceptions. But I would wrap each task in something to catch any Exception subclass and report back to the queue. Untested example: def subwrapper(q, callable, *args, **kwargs): try: q.put

Re: Catching exceptions with multi-processing

2015-06-20 Thread Fabien
On 06/19/2015 10:58 PM, Chris Angelico wrote: AIUI what he's doing is all the subparts of task1 in parallel, then all the subparts of task2: pool.map(task1, dirs, chunksize=1) pool.map(task2, dirs, chunksize=1) pool.map(task3, dirs, chunksize=1) task1 can be done on all of dirs in parallel, as

Re: Catching exceptions with multi-processing

2015-06-19 Thread Cameron Simpson
queue. When it succeeds you put (unique_id, None). In the main process you consume the queue and do your error handling. Note that some exceptions can't be serialized, there is where tblib [0] comes handy. [0]https://pypi.python.org/pypi/tblib Regards, Thanks, I wasn't aw

Re: Catching exceptions with multi-processing

2015-06-19 Thread Chris Angelico
On Sat, Jun 20, 2015 at 1:41 AM, Steven D'Aprano wrote: > On Sat, 20 Jun 2015 12:01 am, Fabien wrote: > >> Folks, >> >> I am developing a tool which works on individual entities (glaciers) and >> do a lot of operations on them. There are many tasks to do, one after >> each other, and each task fol

Re: Catching exceptions with multi-processing

2015-06-19 Thread Fabien
put (unique_id, None). In the main process you consume the queue and do your error handling. Note that some exceptions can't be serialized, there is where tblib [0] comes handy. [0]https://pypi.python.org/pypi/tblib Regards, Thanks, I wasn't aware of the multiprocessing.Queue wo

Re: Catching exceptions with multi-processing

2015-06-19 Thread Fabien
f_dirs] pool.map(task1, dirs, chunksize=1) pool.map(task2, dirs, chunksize=1) pool.map(task3, dirs, chunksize=1) which should be changed to something like (after some of the responses): dirs = [list_of_dirs] pool.map(task1, dirs, ...) # handle exceptions dirs_reduced = [dirs that did not fail] poo

Re: Catching exceptions with multi-processing

2015-06-19 Thread Steven D'Aprano
On Sat, 20 Jun 2015 12:01 am, Fabien wrote: > Folks, > > I am developing a tool which works on individual entities (glaciers) and > do a lot of operations on them. There are many tasks to do, one after > each other, and each task follows the same interface: I'm afraid your description is contrad

Re: Catching exceptions with multi-processing

2015-06-19 Thread Jean-Michel Pichavant
raise ValueError(val) > print(val) > > Just replace the raise statement with whatever you want to do (write > to a file etc). Since all errors are handled in the master process > there are no issues with writing to a file. > > -- > Oscar The main problem wi

Re: Catching exceptions with multi-processing

2015-06-19 Thread Oscar Benjamin
On 19 June 2015 at 15:01, Fabien wrote: > Folks, > > I am developing a tool which works on individual entities (glaciers) and do > a lot of operations on them. There are many tasks to do, one after each > other, and each task follows the same interface: > > def task_1(path_to_glacier_dir): > o

Re: Catching exceptions with multi-processing

2015-06-19 Thread Jean-Michel Pichavant
- Original Message - > From: "Fabien" > To: python-list@python.org > Sent: Friday, 19 June, 2015 4:01:02 PM > Subject: Catching exceptions with multi-processing > > Folks, > > I am developing a tool which works on individual entities (glaciers) >

Re: Catching exceptions with multi-processing

2015-06-19 Thread Andres Riancho
consume the queue and do your error handling. Note that some exceptions can't be serialized, there is where tblib [0] comes handy. [0] https://pypi.python.org/pypi/tblib Regards, On Fri, Jun 19, 2015 at 11:01 AM, Fabien wrote: > Folks, > > I am developing a tool which works

Catching exceptions with multi-processing

2015-06-19 Thread Fabien
Folks, I am developing a tool which works on individual entities (glaciers) and do a lot of operations on them. There are many tasks to do, one after each other, and each task follows the same interface: def task_1(path_to_glacier_dir): open file1 in path_to_glacier_dir do stuff i

Re: try..except with empty exceptions

2015-04-12 Thread Cameron Simpson
On 12Apr2015 17:00, Chris Angelico wrote: On Sun, Apr 12, 2015 at 4:33 PM, Cameron Simpson wrote: [...] That's what try/finally is for. You can do your cleanup without caring exactly what was raised. Hmm, yes. [...] However, my Asynchron class really is a little special. I use Asynchron t

  1   2   3   4   5   6   7   8   9   10   >