On 12/24/2010 3:24 AM, Carl Banks wrote:
On Dec 24, 1:24 am, Steven D'Aprano<steve
+comp.lang.pyt...@pearwood.info>  wrote:
 All I'm
suggesting is that there should be a way of reducing the boilerplate
needed for this idiom:

def _validate_arg(x):
     if x == 'bad input': return False
     return True

def f(arg):
     if not _validate_arg(arg):
         raise ValueError
     process(arg)

to something more natural that doesn't needlessly expose implementation
details that are completely irrelevant to the caller.

    How about

        raise ValueError("Bad input %s to validate_arg" % (repr(arg),))

You can pass arguments to most exceptions, and the content of the
exception is determined entirely by the code raising it.

If end users are seeing uncaught tracebacks, the program is broken.
It's usually worth it to catch EnvironmentError near the outermost
level of the program, since most non program bug events, like I/O
and network errors. will raise some subclass of EnvironmentError.

                                        John Nagle
--
http://mail.python.org/mailman/listinfo/python-list

Reply via email to