6,495 views
この記事は最終更新から 2483日 が経過しています。
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-08-07: 1回 2026-08-06: 0回 2026-08-05: 0回 2026-08-04: 0回 2026-08-03: 0回 2026-08-02: 1回 2026-08-01: 0回