def check(protocol): try: protocol.login("itamar") if protocol.isonline("joe"): print "joe is online" except ValueError: print "something wrong" print "all done"