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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 17, 20262026-06-17T12:08:05+00:00 2026-06-17T12:08:05+00:00

I have the following code: catch(Exception ex) { throw new FatalException(An error occurred while

  • 0

I have the following code:

catch(Exception ex)
{
    throw new FatalException("An error occurred while trying to load the XSLT file.", ex);
}

This unfortunately just swallows up the Exception. I can fix this by doing the following:

catch(Exception ex)
{
    throw;
}

But I would still like to include the custom message for help with event logging.

How do I add this message to the exception without losing any information? (stack trace/debug symbols, etc.)

  • 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-17T12:08:07+00:00Added an answer on June 17, 2026 at 12:08 pm

    If you just need to add information to the original exception, such as a user-readable message or specific details that will be useful to you in tracking down the error but that won’t be useful to the end user, you can make use of the Exception’s Data property, which is a key/value pair dictionary.

    We use this extensively in order to record information such as the report being executed or file that is being processed so that operations can determine what exactly was happening at the time of the error. The user doesn’t need this detail since they are working directly with the cause of the failure.

    You could also use this to pass a plain text message that makes sense to the user. The only issue is that you will have to perform some additional work in your logging framework or end-user interface in order to extract the data and make it useful to the consumer.

    For example, you could do:

    catch (Exception ex)
    {
        ex.Data.Add("UserMessage", "An error occurred while trying to load the XSLT file.");
        throw;
    }
    

    Then in the client-side code, you could test to see if UserMessage exists and, if so, present it to the user instead of the Exception:

    catch (Exception ex)
    {
        if (ex.Data.Contains("UserMessage"))
        {
            MessageBox.Show(ex.Data["UserMessage"].ToString());
        }
        else
        {
            MessageBox.Show(ex.Message);
        }
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have the following piece of code try{//do something } catch (Exception e) {
We have following code: try { // some code throwing MyException } catch (MyException
I have the following piece of code in a try/catch block InputStream inputstream =
If in my code I have the following snippet: try { doSomething(); } catch
I have the following code to upload a pdf file through ftp : try
I have the following code: SaveFileDialog saveGC1File = new SaveFileDialog(); private void GCSavePlacementOneButton_Click(object sender,
I have the following code: try{ using (StreamReader reader = new StreamReader(...), Encoding.ASCII)){ //
I have the following code to encode password field but it gets error when
I have the following code: EventLog el1 = new EventLog(); el1.Log = Application; el1.Source
I have the following code. In that fn2 is actually throwing an exception 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.