# DKUUG PYTHON LECTURE March 25 2008
# Copyright 2008 Svenne Krap. 
# This software is released under the BSD license.
# Please see the attached license

import random

class A:
    pass

class B:
    pass

def fragile_function():
    r = random.random()
    if r < 0.33:
        return random.randint(0,99)
    elif r < 0.66:
        raise A
    else:
        raise B


try:
    print "trying fragile function"
    res = fragile_function()
    print "succeded, result = " + str(res)
except A:
    print "OOPS, A happened"
except B:
    print "OOPS, B happened"
finally:
    print "cleanup"

