6,376 views
この記事は最終更新から 2305日 が経過しています。
throw じゃなくて raise と書く。
########################################################################
class MyError(Exception):
pass
########################################################################
def check_number( n ):
ret = False
try:
if n < 10 :
raise MyError('%d is too small' % n)
if n > 100 :
raise MyError('%d is too big' % n)
ret = True
except MyError as e:
print('<p style="color:#f00">%s</p>' % e.message)
return ret
実行してみる。
>>> check_number(1) <p style="color:#f00">1 is too small</p> False >>> >>> check_number(50) True >>> >>> check_number(200) <p style="color:#f00">200 is too big</p> False
アクセス数(直近7日): ※試験運用中、BOT除外簡易実装済2026-02-10: 0回 2026-02-09: 0回 2026-02-08: 0回 2026-02-07: 2回 2026-02-06: 1回 2026-02-05: 0回 2026-02-04: 0回