Re: Dealing with exceptions

2013-03-03 Thread Nobody
On Sat, 02 Mar 2013 18:52:19 +0100, Kwpolska wrote: > Also, you can do `except:` for a catch-all, but it is discouraged unless > you have REALLY good reasons to do this. And, most of the time, you > don’t. Most of the time you probably want to catch either Exception (which excludes GeneratorExit

Re: Dealing with exceptions

2013-03-02 Thread Steven D'Aprano
On Sat, 02 Mar 2013 11:35:13 -0800, bvdp wrote: >> IOError and OSError should cover all copy problems, I think. > > How do you know that? I can figure it out as well by running the > program, but I'd like to make the determination of what to catch when > I'm writing the code. In my experience,

Re: Dealing with exceptions

2013-03-02 Thread Chris Angelico
On Sun, Mar 3, 2013 at 11:41 AM, Steven D'Aprano wrote: > But yes, in general, only catch the minimum you *know* you need to catch > and can deal with. Anything else is a bug in your code that needs to be > fixed, and you can't fix it if you never see the exception. With the exception (if you'll

Re: Dealing with exceptions

2013-03-02 Thread Steven D'Aprano
On Sat, 02 Mar 2013 18:52:19 +0100, Kwpolska wrote: > Also, you can do `except:` for a catch-all, but it is discouraged unless > you have REALLY good reasons to do this. And, most of the time, you > don’t. `except Exception` is to be much preferred over a bare except. It excludes KeyboardInter

Re: Dealing with exceptions

2013-03-02 Thread Chris Angelico
On Sun, Mar 3, 2013 at 10:08 AM, Terry Reedy wrote: > On 3/2/2013 5:16 PM, Chris Angelico wrote: >> >> On Sun, Mar 3, 2013 at 8:23 AM, Terry Reedy wrote: >> >> open('sdjhfjshdfkjsh') >>> >>> Traceback (most recent call last): >>>File "", line 1, in >>> open('sdjhfjshdfkjsh') >>>

Re: Dealing with exceptions

2013-03-02 Thread Terry Reedy
On 3/2/2013 5:16 PM, Chris Angelico wrote: On Sun, Mar 3, 2013 at 8:23 AM, Terry Reedy wrote: open('sdjhfjshdfkjsh') Traceback (most recent call last): File "", line 1, in open('sdjhfjshdfkjsh') FileNotFoundError: [Errno 2] No such file or directory: 'sdjhfjshdfkjsh' Now, does shutil

Re: Dealing with exceptions

2013-03-02 Thread Chris Angelico
On Sun, Mar 3, 2013 at 8:23 AM, Terry Reedy wrote: open('sdjhfjshdfkjsh') > Traceback (most recent call last): > File "", line 1, in > open('sdjhfjshdfkjsh') > FileNotFoundError: [Errno 2] No such file or directory: 'sdjhfjshdfkjsh' > > Now, does shutil pass on FileNotFoundError? I wil

Re: Dealing with exceptions

2013-03-02 Thread Terry Reedy
On 3/2/2013 12:40 PM, bvdp wrote: But, I know there can be other errors as well. Doing some tests, I know that certain filenames are invalid (I think a "?" or unicode char is invalid when writing to a FAT32 filesystem). And, so what exception is that? Without actually creating the error, I can't

Re: Dealing with exceptions

2013-03-02 Thread Rick Johnson
On Saturday, March 2, 2013 11:40:11 AM UTC-6, bvdp wrote: > Every time I write a program with exception handling (and > I suppose that includes just about every program I write!) > I need to scratch my brain when I create try blocks. > > For example, I'm writing a little program do copy specific >

Re: Dealing with exceptions

2013-03-02 Thread bvdp
> > Here's a bit of a left-field thought: Maybe none of them. > Not far left at all :) > > What are you actually doing when you get an exception? Can you > > plausibly recover? If not - that is, if you're going to abort the > > whole operation anyway - then save yourself the trouble of writi

Re: Dealing with exceptions

2013-03-02 Thread Devin Jeanpierre
On Sat, Mar 2, 2013 at 1:21 PM, Chris Angelico wrote: >> now, I need to figure out just what exceptions to handle. > > Here's a bit of a left-field thought: Maybe none of them. > > What are you actually doing when you get an exception? Can you > plausibly recover? If not - that is, if you're going

Re: Dealing with exceptions

2013-03-02 Thread bvdp
> > IOError and OSError should cover all copy problems, I think. How do you know that? I can figure it out as well by running the program, but I'd like to make the determination of what to catch when I'm writing the code. -- http://mail.python.org/mailman/listinfo/python-list

Re: Dealing with exceptions

2013-03-02 Thread Mark Lawrence
On 02/03/2013 17:58, Ian Kelly wrote: On Sat, Mar 2, 2013 at 10:40 AM, bvdp wrote: Every time I write a program with exception handling (and I suppose that includes just about every program I write!) I need to scratch my brain when I create try blocks. For example, I'm writing a little progr

Re: Dealing with exceptions

2013-03-02 Thread Chris Angelico
On Sun, Mar 3, 2013 at 4:40 AM, bvdp wrote: > For example, I'm writing a little program do copy specific files to a USB > stick. To do the actual copy I'm using: > > try: >shutil.copy(s, os.path.join(usbpath, songname)) > except ... > > now, I need to figure out just what excepti

Re: Dealing with exceptions

2013-03-02 Thread Ian Kelly
On Sat, Mar 2, 2013 at 10:52 AM, Kwpolska wrote: > IOError and OSError should cover all copy problems, I think. And it may be worth pointing out here that as of Python 3.3, IOError is just a synonym for OSError. -- http://mail.python.org/mailman/listinfo/python-list

Re: Dealing with exceptions

2013-03-02 Thread Ian Kelly
On Sat, Mar 2, 2013 at 10:40 AM, bvdp wrote: > Every time I write a program with exception handling (and I suppose that > includes just about every program I write!) I need to scratch my brain when I > create try blocks. > > For example, I'm writing a little program do copy specific files to a U

Re: Dealing with exceptions

2013-03-02 Thread Kwpolska
On Sat, Mar 2, 2013 at 6:40 PM, bvdp wrote: > Every time I write a program with exception handling (and I suppose that > includes just about every program I write!) I need to scratch my brain when I > create try blocks. > > For example, I'm writing a little program do copy specific files to a US

Dealing with exceptions

2013-03-02 Thread bvdp
Every time I write a program with exception handling (and I suppose that includes just about every program I write!) I need to scratch my brain when I create try blocks. For example, I'm writing a little program do copy specific files to a USB stick. To do the actual copy I'm using: try: