[Date Prev][Date Next] [Thread Prev][Thread Next] [Date Index] [Thread Index]

Re: Python or Perl for a Debian maintainance project?



On Mon, Feb 16, 2004 at 03:03:10PM +0100, Julian Mehnle wrote:
> Andrew Suffield wrote:
> > On Sun, Feb 15, 2004 at 09:43:23PM +0100, Matthias Urlichs wrote:
> > > Every error whatsoever throws an exception. That's far better from a
> > > quality POV than to check the error return of
> > > _every_single_statement_, because (a) nobody actually programs that
> > > way, and (b) if you actually do program that way your code will be
> > > twice as long and ten times as unreadable.
> > 
> > However, it results in code that throws exceptions to the user rather
> > than useful error messages, which is amateurish. The user should never
> > see an exception unless there is a bug in your code; errors from the
> > system should be handled properly. This *does* make your code twice as
> > long, but it will not make it any less readable if you do it
> > right. Failing to do it is like failing to test your code before
> > releasing it, or trusting data read from the network - it is not
> > something that has any place in a serious program.
> 

> That's an invalid conclusion.  In every language that supports
> exceptions, you can very well have a global exception handler that
> catches any uncaught exceptions and presents them to the user in a
> nice way.

No you can't. I'd be mildly interested in seeing a handler that could
handle any exception and generate a suitable error message that was
not of infinite length (because it can't be done).

Note that you have to do this for exceptions you receive from things
you call.

Here's a suitably contrived example that can't be simulated in the way
you describe:

if (open $foo, $bar)
  {
    /* do stuff */
    return 1;
  }
die "Failed to open $bar: $!" unless $! == ENOENT;

if (open $foo, $baz)
  {
    /* do stuff */
    return 1;
  }
die "Failed to open $baz: $!" unless $! == ENOENT;

print STDERR "Neither $bar nor $baz were found\n";
return 1;

Here the "special" (common) case of two non-existant files has been
handled differently to generate an informative error.

-- 
  .''`.  ** Debian GNU/Linux ** | Andrew Suffield
 : :' :  http://www.debian.org/ |
 `. `'                          |
   `-             -><-          |

Attachment: signature.asc
Description: Digital signature


Reply to: