[Baypiggies] Python way to avoid usage of raise

Brent Tubbs brent.tubbs at gmail.com
Wed Oct 6 23:28:43 CEST 2010


Nick: Is your boss likely to notice something like this?

(except.py)
class TotallyNotAnExceptionNothingToSeeHere(Exception):
    pass

raise TotallyNotAnExceptionNothingToSeeHere("Really, pay me no attention")

brent at greta:~/tmp$ python except.py
Traceback (most recent call last):
  File "except.py", line 4, in <module>
    raise TotallyNotAnExceptionNothingToSeeHere("Really, pay me no attention")
__main__.TotallyNotAnExceptionNothingToSeeHere: Really, pay me no attention

Kidding.... mostly.  The "no exceptions" rule just seems really arbitrary.

Brent

On Wed, Oct 6, 2010 at 8:01 AM, Andrew Dalke <dalke at dalkescientific.com> wrote:
> On Oct 5, 2010, at 9:57 PM, James Tatum wrote:
>> I've seen this anti-pattern up close. There is no Pythonic answer -
>> exceptions are the answer.
>
> There is a Pythonic answer - you can go the Twisted route.
> (Excepting those who think Twisted isn't Pythonic. ;)
>
> Twisted's Deferreds can't use the stack because they
> implement continuations through callback methods. You
> "addCallback" for the normal case and "addErrback" for the
> exceptions.
>
> It's possible to develop your entire code base this way.
>
> It's going to be structured entirely different than what
> the OP's more senior rule mandator expects, but that might
> be a good thing here.
>
>
>                                Andrew
>                                dalke at dalkescientific.com
>
>
> _______________________________________________
> Baypiggies mailing list
> Baypiggies at python.org
> To change your subscription options or unsubscribe:
> http://mail.python.org/mailman/listinfo/baypiggies
>


More information about the Baypiggies mailing list