Why should I always make my Exceptions [serializable]? (.NET)

前端 未结 4 2004
再見小時候
再見小時候 2020-11-27 04:58

Referring to What is the correct way to make a custom .NET Exception serializable?
and Are all .NET Exceptions serializable? ...

Why should my exceptio

4条回答
  •  北海茫月
    2020-11-27 05:43

    I think that the default for all classes should be Serializable unless they contain a class that is explicitly not serializable. It's annoying to not be able to transfer a class just because some designer didn't think about it.

    The same thing with "Final", all variables should be "Final" by default unless you specifically say that they are "Mutable".

    Also, I'm not sure it makes sense to have a variable that is not private.

    Oh well, need to design my own language.

    But the answer is, you don't know how your exception will be used and they are assumed to be able to be thrown across remote calls.

提交回复
热议问题