How to make a custom exception class with multiple init args pickleable

前端 未结 4 1404
醉梦人生
醉梦人生 2021-01-31 02:46

Why does my custom Exception class below not serialize/unserialize correctly using the pickle module?

import pickle

class MyException(Exception):
    def __ini         


        
4条回答
  •  被撕碎了的回忆
    2021-01-31 03:43

    I simply do this

    class MyCustomException(Exception):
        def __init__(self):
            self.value = 'Message about my error'
    
        def __str__(self):
            return repr(self.value)
    
    ... somewhere in code ...
    raise MyCustomException
    

提交回复
热议问题