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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 1, 20262026-06-01T10:25:11+00:00 2026-06-01T10:25:11+00:00

I have created a custom exception however when it is fired, I’m not getting

  • 0

I have created a custom exception however when it is fired, I’m not getting the message I expect.

Instead of the Unhandled Execution Error message I am expecting the override in my custom class to fire which would be The section 'UIButtons' does not contain an element with element key 'Save' based on the exception being thrown below.

Can anyone help me diagnose why this is happening?

using System;

namespace Payntbrush.Infrastructure.Application.Exceptions.Configuration
{
    [Serializable]
    public class ConfigElementDoesNotExistException : Exception
    {
        private string _sectionName;
        private string _elementName;

        public ConfigElementDoesNotExistException(string sectionName, string elementName, string errorMessage = "")
                             : base(errorMessage)
        {
            _sectionName = sectionName;
            _elementName = elementName;
        }

        public ConfigElementDoesNotExistException(string sectionName, string elementName, string errorMessage, Exception innerEx)
                             : base(errorMessage, innerEx)
        {
            _sectionName = sectionName;
            _elementName = elementName;
        }

        /// <summary>
        /// Gets a message that describes the current exception
        /// </summary>
        public override string Message
        {
            get
            {
                string exceptionMessage;

                if (String.IsNullOrEmpty(base.Message))
                {
                    exceptionMessage = base.Message;
                }
                else
                {
                    exceptionMessage = String.Format("The section '{0}' does not contain an element with element key '{1}'", _sectionName, _elementName);
                }

                return exceptionMessage;
            }
        }
    }
}

To throw it I am using:

throw new ConfigElementDoesNotExistException("UIButtons", "Save");

And when it fires I get this message

Unhandled Execution Error

Description: An unhandled exception occurred during the execution of the current web request. Please review the stack trace for more information about the error and where it originated in the code. 

Exception Details: Payntbrush.Infrastructure.Application.Exceptions.Configuration.ConfigElementDoesNotExistException: 
  • 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-01T10:25:13+00:00Added an answer on June 1, 2026 at 10:25 am

    I think you should change the if statement in your get override of Message to:

    if (!String.IsNullOrEmpty(base.Message)) 
    

    Note the !.

    At present, if the message supplied on construction is null or empty, then you’re returning null/empty – so the framework is filling in it’s own when reporting the exception.

    Presumably you meant to supply your own message if it’s null/empty.

    Minor update – advisory

    Incidentally – I generally do this kind of thing in the constructor:

    public MyException(string message) : base(message ?? "Default message") { }
    

    In your case I would do it like this with just one constructor:

    public ConfigElementDoesNotExistException(string sectionName, 
                                              string elementName, 
                                              string errorMessage = null, 
                                              Exception innerEx = null)   
    : base(errorMessage ?? string.Format("The section {0} doesn't ... {1}", 
                           sectionName ?? "[unknown]", elementName ?? "[unknown]")
           , innerEx)   
    {   
      _sectionName = sectionName;   
      _elementName = elementName;   
    }   
    

    Also don’t forget the protected constructor and GetObjectData override to ensure your exception can be saved/loaded and marshalled properly.

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

Sidebar

Related Questions

I have a web service in which I have created a custom exception. Let's
I have created custom posts and I want one page in my site to
I have created custom jQuery UI widget called uiPopover, very similar to UI-dialog (in
I have created custom cell in which there are n number of image views.
friends, i have created custom title bar using following titlebar.xml file with code <?xml
I have created a custom list as a feature in sharepoint. i need to
I have created a custom ExpandableListAdapter and everything works properly. What I'd like to
I have created a custom workflow activity that copies attachments from a case to
I have created a custom tag that looks like this: def textField = {
I have created a custom style and template for MenuItem and ContextMenu, and for

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.