0

I have been using basic c# mainly for Unity3d but recently started picking it up bit more. While reading about idiomatic handling exceptions I came across exception serialization. I am trying to figure out why should I be serializing them.

Here is sample code from another thread.

using System;
using System.Runtime.Serialization;

[Serializable]
public class MyException : Exception
{
    // Constructors
    public MyException(string message) 
        : base(message) 
    { }

    // Ensure Exception is Serializable
    protected MyException(SerializationInfo info, StreamingContext ctxt) 
        : base(info, ctxt)
    { }
}

I can't see how it could be useful to serialize exceptions. When and why does it make sense to do so?

FullStackForger
  • 1,060
  • 2
  • 12
  • 18
  • 1
    Thanks @adriano-repetti – FullStackForger May 22 '17 at 17:55
  • It's important to add the Serializable attribute which make sure that your exception can be serialized and works correctly across application domains( for example, when a web service return an exception). – Akhilesh May 22 '17 at 17:59

0 Answers0