| ||||||
>>> class bizimHata(Exception): ... def __init__(self, deger): ... self.deger = deger ... def __str__(self): ... return `self.deger` ... >>> try: ... raise bizimHata(2*2) ... except bizimHata, e: ... print 'İstisnamız oluştu, deger:', e.deger ... İstisnamız oluştu, deger: 4 >>> raise bizimHata, 'aaah!' Traceback (most recent call last): File "<stdin>", line 1, in ? __main__.bizimHata: 'aaah!'
class Error(Exception):
"""Bu modüldeki istisnalar için temel sınıf."""
pass
class GirisHatasi(Error):
"""Giriş hataları için oluşacak istisna.
Özellikler:
ifade -- hatanın oluştuğu giriş ifadesi
mesaj -- explanation of the error
"""
def __init__(self, ifade, mesaj):
self.ifade = ifade
self.mesaj = mesaj
class GecisHatasi(Error):
"""İzin verilmeyen bir durum geçişine teşebbüs edildiğinde oluşacak istisna.
Özellikler:
onceki -- geçiş başlangıcındaki durum
sonraki -- istenen yeni durum
mesaj -- durum geçişine izin verilmemesinin sebebi
"""
def __init__(self, onceki, sonraki, mesaj):
self.onceki = onceki
self.sonraki = sonraki
self.mesaj = mesaj
| |||||||||