6,413 views
この記事は最終更新から 2373日 が経過しています。
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-04-19: 0回 2026-04-18: 0回 2026-04-17: 1回 2026-04-16: 0回 2026-04-15: 0回 2026-04-14: 0回 2026-04-13: 0回