Language Python
(Exception based)
Date: | 02/08/08 |
Author: | Michael Galpin |
URL: | http://fupeg.blogspot.com |
Comments: | 0 |
Info: | http://www.python.org/ |
Score: | (2.81 in 27 votes) |
#! /usr/bin/env python class BottleException(Exception): def __init__(self, i, c): self.cause = c self.cnt = i try: a = 1/(99-i) raise BottleException(i+1, self) except ZeroDivisionError: pass def getCause(self): return self.cause def printStackTrace(self): print("%d Bottle(s) of beer on the wall, %d Bottle(s) of beer" % (self.cnt, self.cnt)) print("Take one down and pass it around,") print("%d Bottle(s) of beer on the wall" % (self.cnt - 1)) try: self.getCause().printStackTrace() except AttributeError: pass try: raise BottleException(1, None) except Exception, e: e.printStackTrace()
Download Source | Write Comment
Alternative Versions
Version | Author | Date | Comments | Rate |
---|---|---|---|---|
This example demonstrates the simplicity | Gerold Penz | 07/23/05 | 15 | |
Creative version | Schizo | 11/06/05 | 16 | |
Advanced, extensible beer/wall framework | Jamie Turner | 05/17/06 | 7 | |
minimal version | Oliver Xymoron | 04/20/05 | 5 | |
using lambda in LISP style | J Adrian Zimmer | 11/14/06 | 2 | |
functional, w/o variables or procedures | Ivan Tkatchev | 07/14/05 | 2 | |
minimal version with singular | Emlyn Jones | 06/13/05 | 3 | |
Fully compliant version | Ricardo Garcia Gonzalez | 01/15/06 | 7 | |
Using a iterator class | Eric Moritz | 01/20/06 | 2 | |
New conditional expressions in 2.5 | Ezequiel Pochiero | 12/18/06 | 1 |
Download Source | Write Comment
Add Comment
Please provide a value for the fields Name,
Comment and Security Code.
This is a gravatar-friendly website.
E-mail addresses will never be shown.
Enter your e-mail address to use your gravatar.
Please don't post large portions of code here! Use the form to submit new examples or updates instead!
Comments