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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 19, 20262026-05-19T15:09:03+00:00 2026-05-19T15:09:03+00:00

I have a Membership exception which looks like this: public enum MembershipError { EmailNotFound,

  • 0

I have a Membership exception which looks like this:

public enum MembershipError
{
    EmailNotFound,
    EmailNotConfirmed,
    IncorrectPassword,
    EmailExists
}

public class MembershipException : ApplicationException
{
    public MembershipError MembershipError { get; set; }

    public MembershipException(MembershipError membershipError)
        : base(Enum.GetName(typeof (MembershipError), membershipError))
    {
        MembershipError = membershipError;
    }
}

Should I use an enum in my exception or make an exception for each enum? Because then I would be putting logic when catching the exception like this:

try
{

}
catch (MembershipException exception)
{
    switch (exception.MembershipError)
    {
        case MembershipError.EmailExists:

            break;
            //etc.
    }
}

My service layer throws these exceptions, the web layer/in the action catches these, generate the proper json and return it to the view.
Suggest an alternative please?

  • 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-19T15:09:03+00:00Added an answer on May 19, 2026 at 3:09 pm

    Exceptions should only be used for exceptional situations. The errors listed in your enumeration appear to be fairly standard and I would choose not to express them through an exception. Instead I would prefer TryXXX style API over exceptions.

    For example

    public bool TryGetMembershipData(
      string user, 
      out Data data, 
      out MemberShipError error) {
      ...
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a Controller that currently looks like this: public ActionResult Index() { var
I have code that looks like the following in a class that extends MembershipProvider
I have this membership site setup on my local machine using the ASP.NET membership
I have a view which accepts the following model: Inherits=System.Web.Mvc.ViewPage<MVC_WordsByME.Models.JobCreationModel> This posts back to
I have two sites running which share a membership provider. One of them is
I have a membership site in beta right now... At the moment, when a
I have implemented Membership Provider in my ASP.NET MVC app. Membership provider has the
I use declarative roles in my MVC.NET controllers and I have a custom membership
I have built a custom membership provider that I have used in a previous
I have had a working asp.net 4 membership wesite for about 5 months and

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.