Re: Best Way to Handle All Exceptions

2009-07-15 Thread Jean
On Jul 13, 6:26 am, seldan24 wrote: > Hello, > > I'm fairly new at Python so hopefully this question won't be too > awful.  I am writing some code that will FTP to a host, and want to > catch any exception that may occur, take that and print it out > (eventually put it into a log file and perform

Re: Best Way to Handle All Exceptions

2009-07-15 Thread Steven D'Aprano
On Tue, 14 Jul 2009 08:53:33 -0700, Carl Banks wrote: > On Jul 14, 2:14 am, Steven D'Aprano > wrote: >> On Tue, 14 Jul 2009 01:30:48 -0700, Carl Banks wrote: >> > Seriously, do you *ever* take more than 2 seconds to consider whether >> > you might be missing something obvious before following up

Re: Best Way to Handle All Exceptions

2009-07-14 Thread Piet van Oostrum
> Carl Banks (CB) wrote: >CB> On Jul 14, 4:48 am, Lawrence D'Oliveiro central.gen.new_zealand> wrote: >>> In message <93f6a517-63d8-4c80- >>> >>> bf19-4614b7099...@m7g2000prd.googlegroups.com>, Carl Banks wrote: >>> > Or would you rather let all unexpected exceptions print to standard >>> >

Re: Best Way to Handle All Exceptions

2009-07-14 Thread Carl Banks
On Jul 14, 4:48 am, Lawrence D'Oliveiro wrote: > In message <93f6a517-63d8-4c80- > > bf19-4614b7099...@m7g2000prd.googlegroups.com>, Carl Banks wrote: > > Or would you rather let all unexpected exceptions print to standard > > error, which is often a black hole in non-interactive sitations? > > Si

Re: Best Way to Handle All Exceptions

2009-07-14 Thread Carl Banks
On Jul 14, 2:14 am, Steven D'Aprano wrote: > On Tue, 14 Jul 2009 01:30:48 -0700, Carl Banks wrote: > > Seriously, do you *ever* take more than 2 seconds to consider whether > > you might be missing something obvious before following up with these > > indignant knee-jerk responses? > > Obviously no

Re: Best Way to Handle All Exceptions

2009-07-14 Thread Lawrence D'Oliveiro
In message , seldan24 wrote: > For this particular script, all exceptions are fatal > and I would want them to be. I just wanted a way to catch them and > log them prior to program termination. You don't need to. They will be written to standard error anyway. -- http://mail.python.org/mailman/

Re: Best Way to Handle All Exceptions

2009-07-14 Thread Lawrence D'Oliveiro
In message <93f6a517-63d8-4c80- bf19-4614b7099...@m7g2000prd.googlegroups.com>, Carl Banks wrote: > Or would you rather let all unexpected exceptions print to standard > error, which is often a black hole in non-interactive sitations? Since when? Cron, for example, collects standard error and ma

Re: Best Way to Handle All Exceptions

2009-07-14 Thread Steven D'Aprano
On Tue, 14 Jul 2009 01:30:48 -0700, Carl Banks wrote: > Seriously, do you *ever* take more than 2 seconds to consider whether > you might be missing something obvious before following up with these > indignant knee-jerk responses? Obviously not. [...] > Or would you rather let all unexpected ex

Re: Best Way to Handle All Exceptions

2009-07-14 Thread Carl Banks
On Jul 13, 8:25 pm, Steven D'Aprano wrote: > On Mon, 13 Jul 2009 17:49:23 -0700, Carl Banks wrote: > > On Jul 13, 12:31 pm, Piet van Oostrum wrote: > >> > seldan24 (s) wrote: > >> >s> Hello, > >> >s> I'm fairly new at Python so hopefully this question won't be too s> > >> >awful.  I am writi

Re: Best Way to Handle All Exceptions

2009-07-14 Thread Ben Finney
Steven D'Aprano writes: > Isn't that risky though? Won't that potentially change the exception- > handling behaviour of functions and classes he imports from other > modules? No, any existing ‘except’ clause will be unaffected by re-binding ‘sys.excepthook’. As I understand the documentation, th

Re: Best Way to Handle All Exceptions

2009-07-13 Thread Steven D'Aprano
On Tue, 14 Jul 2009 10:09:06 +1000, Ben Finney wrote: > Instead of catching *all* exceptions at a specific point in your code, > and then having nothing to do but end the program (possibly after some > pre-exit action like logging), I think you would be better served by > installing a custom top-l

Re: Best Way to Handle All Exceptions

2009-07-13 Thread Steven D'Aprano
On Mon, 13 Jul 2009 17:49:23 -0700, Carl Banks wrote: > On Jul 13, 12:31 pm, Piet van Oostrum wrote: >> > seldan24 (s) wrote: >> >s> Hello, >> >s> I'm fairly new at Python so hopefully this question won't be too s> >> >awful.  I am writing some code that will FTP to a host, and want to s> >>

Re: Best Way to Handle All Exceptions

2009-07-13 Thread Carl Banks
On Jul 13, 12:31 pm, Piet van Oostrum wrote: > > seldan24 (s) wrote: > >s> Hello, > >s> I'm fairly new at Python so hopefully this question won't be too > >s> awful.  I am writing some code that will FTP to a host, and want to > >s> catch any exception that may occur, take that and print it o

Re: Best Way to Handle All Exceptions

2009-07-13 Thread Ben Finney
seldan24 writes: > I'm fairly new at Python so hopefully this question won't be too > awful. I am writing some code that will FTP to a host, and want to > catch any exception that may occur, take that and print it out > (eventually put it into a log file and perform some alerting action). You h

Re: Best Way to Handle All Exceptions

2009-07-13 Thread Terry Reedy
Diez B. Roggisch wrote: The latter is - unfortunately - the better. This comes from python allowing all kinds of objects being thrown as exceptions, not only those extending from a common ancestor like Exception. Fixed in Python 3. exceptions, without exceptions, are instances of BaseExceptio

Re: Best Way to Handle All Exceptions

2009-07-13 Thread Piet van Oostrum
> seldan24 (s) wrote: >s> Hello, >s> I'm fairly new at Python so hopefully this question won't be too >s> awful. I am writing some code that will FTP to a host, and want to >s> catch any exception that may occur, take that and print it out >s> (eventually put it into a log file and perform s

Re: Best Way to Handle All Exceptions

2009-07-13 Thread Vilya Harvey
2009/7/13 seldan24 : > Thank you both for your input.  I want to make sure I get started on > the right track.  For this particular script, I should have included > that I would take the exception contents, and pass those to the > logging module.  For this particular script, all exceptions are fata

Re: Best Way to Handle All Exceptions

2009-07-13 Thread Floris Bruynooghe
On Jul 13, 2:26 pm, seldan24 wrote: > The first example: > > from ftplib import FTP > try: >     ftp = FTP(ftp_host) >     ftp.login(ftp_user, ftp_pass) > except Exception, err: >     print err *If* you really do want to catch *all* exceptions (as mentioned already it is usually better to catch s

Re: Best Way to Handle All Exceptions

2009-07-13 Thread seldan24
On Jul 13, 10:33 am, MRAB wrote: > seldan24 wrote: > > Hello, > > > I'm fairly new at Python so hopefully this question won't be too > > awful.  I am writing some code that will FTP to a host, and want to > > catch any exception that may occur, take that and print it out > > (eventually put it int

Re: Best Way to Handle All Exceptions

2009-07-13 Thread MRAB
seldan24 wrote: Hello, I'm fairly new at Python so hopefully this question won't be too awful. I am writing some code that will FTP to a host, and want to catch any exception that may occur, take that and print it out (eventually put it into a log file and perform some alerting action). I've fi

Re: Best Way to Handle All Exceptions

2009-07-13 Thread Diez B. Roggisch
seldan24 wrote: > Hello, > > I'm fairly new at Python so hopefully this question won't be too > awful. I am writing some code that will FTP to a host, and want to > catch any exception that may occur, take that and print it out > (eventually put it into a log file and perform some alerting actio

Best Way to Handle All Exceptions

2009-07-13 Thread seldan24
Hello, I'm fairly new at Python so hopefully this question won't be too awful. I am writing some code that will FTP to a host, and want to catch any exception that may occur, take that and print it out (eventually put it into a log file and perform some alerting action). I've figured out two diff