Voting

Category

real language

Bookmarking

Del.icio.us Digg Diigo DZone Earthlink Google Kick.ie
Windows Live LookLater Ma.gnolia Reddit Rojo StumbleUpon Technorati

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.62 in 24 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

VersionAuthorDateCommentsRate
This example demonstrates the simplicityGerold Penz07/23/0515
Creative versionSchizo11/06/0516
Advanced, extensible beer/wall frameworkJamie Turner05/17/067
minimal versionOliver Xymoron04/20/055
functional, w/o variables or proceduresIvan Tkatchev07/14/052
using lambda in LISP styleJ Adrian Zimmer11/14/062
Fully compliant versionRicardo Garcia Gonzalez01/15/067
Using a iterator classEric Moritz01/20/062
minimal version with singularEmlyn Jones06/13/053
New conditional expressions in 2.5Ezequiel Pochiero12/18/061

Comments

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!

Name:

eMail:

URL:

Security Code:
  
Comment: