Proper way to declare custom exceptions in modern Python?

后端 未结 11 1868
栀梦
栀梦 2020-11-22 08:04

What\'s the proper way to declare custom exception classes in modern Python? My primary goal is to follow whatever standard other exception classes have, so that (for instan

11条回答
  •  暗喜
    暗喜 (楼主)
    2020-11-22 08:22

    You should override __repr__ or __unicode__ methods instead of using message, the args you provide when you construct the exception will be in the args attribute of the exception object.

提交回复
热议问题