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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 2, 20262026-06-02T15:30:31+00:00 2026-06-02T15:30:31+00:00

I’ve googled for quiet a time now and I still don’t know which exception

  • 0

I’ve googled for quiet a time now and I still don’t know which exception to use in which scenario. I’ve read that it’s bad practice to raise SystemExceptions in your own code, because those exception should better get raised by the CLR.

But well, now I want to know what Exeption I should raise in different scenarios. Let’s say I have a method which gets invoked with an enum as Parameter. That isn’t a very good example – it just came off the top of my head.

public enum CommandAppearance
{
    Button,
    Menu,
    NotSpecified
}

//...

public void PlaceButtons(CommandAppearance commandAppearance)
{
    switch(commandAppearance)
    {
        case CommandAppearance.Button:
            // do the placing
        case CommandAppearance.Menu:
            // do the placing
        case CommandAppearance.NotSpecified:
            throw ArgumentOutOfRangeException("The button must have a defined appearance!")
    }
}

What would it be here? Is there some kind of site, where I can get an overview? Are there any patterns which tell you what kind of exception to raise? I’d just need some tips at this topic, because I’m pretty unconfident with this.

I think raising just new Exception()s isn’t good practice, either, is it?

  • 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-06-02T15:30:33+00:00Added an answer on June 2, 2026 at 3:30 pm

    For your example scenario, I would suggest either:

    • ArgumentOutOfRangeException if the method supports ALL values in the enum and an invalid value is passed.
    • NotSupportedException if the method supports a subset of the values in the enum.

    Generally speaking, you want to make use of the exception types See this list of exceptions in the .net framework where possible and it makes sense, otherwise you want to introduce your own. This may involve adding a common application exception for your application and adding more specific ones which inherit from it.

    e.g.

    public class MyAppException : Exception
    {
        // This would be used if none of the .net exceptions are appropriate and it is a 
        // generic application error which can't be handled differently to any other 
        // application error.
    }
    
    public class CustomerStatusInvalidException : MyAppException
    {
        // This would be thrown if the customer status is invalid, it allows the calling
        // code to catch this exception specifically and handle it differently to other 
        // exceptions, alternatively it would also be caught by (catch MyAppException) if 
        // there is no (catch CustomerStatusInvalidException).
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I am trying to understand how to use SyndicationItem to display feed which is
I'm parsing an RSS feed that has an ’ in it. SimpleXML turns this
link Im having trouble converting the html entites into html characters, (&# 8217;) i
That's pretty much it. I'm using Nokogiri to scrape a web page what has
I used javascript for loading a picture on my website depending on which small
I have a jquery bug and I've been looking for hours now, I can't
I have a string like this: La Torre Eiffel paragonata all’Everest What PHP function
this is what i have right now Drawing an RSS feed into the php,
I've got a string that has curly quotes in it. I'd like to replace
I have a French site that I want to parse, but am running into

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.