自定義例外

建立自己的例外類別。

class NegativeError(Exception):
    pass

if x < 0:
    raise NegativeError("不接受負數")
💻 程式碼編輯器
📤 執行結果
等待執行...
← 上一課 完成本等級 ✓