logo
  • 教程列表
  • SO官方文檔
  • 提出自定義錯誤異常
    • 自定義異常
    • 捕獲自定義異常
  1. StackOverflow 文件
  2. Python Language 教程
  3. 提出自定義錯誤異常
  4. 捕獲自定義異常

捕獲自定義異常

Created: November-22, 2018

此示例顯示如何捕獲自定義 Exception

class CustomError(Exception):
     pass

try:
    raise CustomError('Can you catch me ?')
except CustomError as e:
    print ('Catched CustomError :{}'.format(e))
except Exception as e:
    print ('Generic exception: {}'.format(e))

輸出:

Catched CustomError :Can you catch me ?
  • 自定義異常

Copyright © 2018. All right reserved

tastones.com 备案号:鲁ICP备18045372号-1

  • 關於本站
  • 免責聲明