Skip to content

Latest commit

 

History

History

q22b_raise

Folders and files

NameName
Last commit message
Last commit date

parent directory

..
 
 
 
 
title course
Raise 拋出例外
S2 - Intermediate Python Programming
  • 可以使用 raise 語句拋出例外,語法如下:

    raise [例外類型[(e)]]
def checkZeroNumber(num):
    if num > 0:
        raise Exception("數值大於0")
    if num < 0:
        raise Exception("數值小於0")

checkZeroNumber(1)
Exception: 數值大於0