Re: error handling in Python

From: John Roth (newsgroups_at_jhrothjr.com)
Date: 05/05/04


Date: Wed, 5 May 2004 16:55:41 -0400


<beliavsky@aol.com> wrote in message
news:3064b51d.0405050741.43d11aa0@posting.google.com...
> Suppose I have a function
>
> def read_data(xfile):
> # code here to read dates and prices
> return dates,prices
>
> that if successful returns two Numeric arrays, of dates and prices.

It looks like you're still thinking in Fortran. It's probably going to
be easier all around to return one list of two element tuples.

> I am unsure what to return if read_data is unsucessful. Since a
> successful function call returns a list of length two, I could return
> a list of length one if there is a problem, so that [-1] is returned
> if the file does not exist, [-2] if the dates are invalid, etc. After
> calling the function, I could check the len of the result to detect
> problems. This seems workable but ad-hoc.

> I do NOT want to use the try/except idiom to stop the program if there
> is a problem reading data.
>
> In Fortran I would write a subroutine with calling sequence
>
> call read_data(xfile,dates,prices,ierr)
>
> where ierr would be checked upon return for nonzero values.

The basic question is: what do you want to do with an error?
That conditions how you want to handle it. Do you want to print
an error message and quit? Print an error message and continue
with the next batch? Fake up a return so the rest of the program
continues as if nothing was wrong?

John Roth



Relevant Pages

  • Re: Disk errors using ANALYZE or DIAGNOSE
    ... This is the first issue, GENERIC DK, so not a recognized VMS device [for ... extended sense data into something meaningful. ... > normal successful completion. ... > the vendor or just ignore an error message. ...
    (comp.os.vms)
  • Re: ConnectComputer Conundrum
    ... and re-installing did not change the symptoms. ... ConnectComputer wizard can proceed so successfully yet leave such a generic ... Internet functions are also successful at the ... >> with the generic error message about configuring networking. ...
    (microsoft.public.windows.server.sbs)
  • Re: AppDatalocal empyayxuogd.dll
    ... Did you recently have a malware infection that you think you have cleaned out? ... It appears you were not entirely successful. ... Windows Desktop Experience ... The error message appears every time I log-on to my computer. ...
    (microsoft.public.windows.vista.performance_maintenance)
  • error handling in Python
    ... that if successful returns two Numeric arrays, of dates and prices. ... In Fortran I would write a subroutine with calling sequence ...
    (comp.lang.python)
  • Re: Error message
    ... The error message is: #N/B. ... equivalent in English will be #N/A. Leaving False out of the formula results ... which refers to the list of bonds in the first ws. ... COLUMN= column in first ws with the prices of the individual ...
    (microsoft.public.excel.worksheet.functions)