Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 276703
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 12, 20262026-05-12T00:57:47+00:00 2026-05-12T00:57:47+00:00

The answer to What is the correct way to make exceptions serializable? says that

  • 0

The answer to What is the correct way to make exceptions serializable? says that the “correct” base implementation for a custom exception includes 4 ctors:

[Serializable]
public class SerializableExceptionWithoutCustomProperties : Exception
{
    public SerializableExceptionWithoutCustomProperties()
    {
    }

    public SerializableExceptionWithoutCustomProperties(string message) 
        : base(message)
    {
    }

    public SerializableExceptionWithoutCustomProperties(string message, Exception innerException) 
        : base(message, innerException)
    {
    }

    // Without this constructor, deserialization will fail
    protected SerializableExceptionWithoutCustomProperties(SerializationInfo info, StreamingContext context) 
        : base(info, context)
    {
    }
}

Right off the bat, I’d say that’s a really bad name for an Exception type. But, beyond that,

  1. For purposes of binary serialization, which is what the SO question was referring to, must I implement all 4 constructors? I think for purposes of [Serializable], I must provide a ctor that accepts 2 args of type (SerializationInfo, StreamingContext), because the exception derives from System.Exception, which itself does custom serialization. I can understand that. But must I implement the other ctors, in order to properly provide a serializable exception? I know that if I want to allow a type to be xml-serializable, I need to provide the default (no-op) ctor. Is the same true for [Serializable]? For a moment, let’s confine ourselves to the narrow concern of [Serializable], and leave aside any broader guidelines regarding “framework design”.

  2. Moving to the broader question: The guidelines say that custom exceptions should implement the 4 common ctors. What is the reasoning behind this guideline? If I design a custom exception, is it really bad manners, or even a bug, if I don’t provide a null/default ctor? Is it really bad manners, or even a bug, if I don’t provide a ctor that allows an innerException? Why? Consider the case that my custom exception is generated within my library code, and the only instances I ever throw include a message, and no innerException.

  3. In short, is the following code acceptable for a custom exception that provides no additional properties?


[Serializable]
public class CustomException : Exception
{
    public CustomException(string message) : base(message) { }

    // Without this constructor, deserialization will fail
    protected CustomException(SerializationInfo info, StreamingContext context) 
        : base(info, context) { }
}

see also: Winterdom blog: Make exceptions Serializable.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-12T00:57:48+00:00Added an answer on May 12, 2026 at 12:57 am

    I didn’t like any of the answers. I’m settling on my proposed solution, which is .. that I can eliminate the “normal” constructors on my custom exception, including the default constructor and the nested constructor. Also, I need to make sure serialization works, because of cross-appdomain calls.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

No related questions found

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.