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 5999315
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 23, 20262026-05-23T00:32:06+00:00 2026-05-23T00:32:06+00:00

What are the pros and cons of implementing a custom exception as follows: Create

  • 0

What are the pros and cons of implementing a custom exception as follows:
Create an enum which represents error messages in its descriptions:

public class Enums
{
    public enum Errors
    {
        [Description("This is a test exception")]
        TestError,
        ...
    }
}

Create a custom exception class:

public class CustomException : ApplicationException
{
    protected Enums.Errors _customError;
    public CustomException(Enums.Errors customError)
    {
        this._customError = customError;
    }
    public override string Message
    {
        get
        {
            return this._customError!= Enums.Errors.Base ? this.customError.GetDescription() : base.Message;
        }
    }  
}  

The GetDescription method is an enum extension method which gets the enum description using reflection. This way, I can throw exception like:

throw new customException(enums.Errors.TestError);  

And show it to the user in catch block like:

Console.WriteLn(ex.Message);  

I’ve seen this approach recommended by an MVP. What are the benefits of this approach over the followings:

  • Using generic exception: throw new Exception(“Error Message”);.
  • Using Custom Exception: Define custom exceptions for any situation. e.g. (WebServiceException class, AuthenticationException class, etc.)

Here’s the link to the recommendation by the MVP.

Thank you.

  • 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-23T00:32:06+00:00Added an answer on May 23, 2026 at 12:32 am

    Personally, i don’t think it’s a good idea.

    You should always throw as specific exceptions as possible. The same goes for catching.

    It’s easy to decide if we want to catch a WebServiceException or AuthenticationException, but with your Enum-example, we have to parse a string to decide if we want to catch it or not. What happens if this message changes?

    I don’t think it has any benefits at all. For each error type, you have to create a new Enum member. Why not create a new class instead?

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

Sidebar

Related Questions

I wonder what's the pros/cons of using delegate vs OOP when implementing strategy design
What are the pros/cons of using the GIT as opposed to CoMarshalInterThreadInterfaceInStream and CoGetInterfaceAndReleaseStream
What are some pros/cons for using the Reflection.Emit library versus CodeDOM for dynamically generating
TLDR: What are the pros/cons of using an in-memory database vs locks and concurrent
Are there any pros/cons of using the following two alternatives in your action signature:
This is more a question of pros/cons between PHP and JAVA. Iv been doing
Is it good to use float in table less design? What is the pros/cons
What's the pros and cons of using a Model-View-Controller model in building your application?
What are the pros and cons of using Qt containers ( QMap , QVector
What's the pros and cons for each of them?

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.