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

  • Home
  • SEARCH
  • 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 5979631
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 22, 20262026-05-22T21:41:12+00:00 2026-05-22T21:41:12+00:00

I maintain an application that sends me an email when an error occurs in

  • 0

I maintain an application that sends me an email when an error occurs in the application. I dump the stack trace into the email, and it seems to work ok. The only thing missing is the values of the variables. I get all the calls and such, just never any variables. What am I missing in order to get these variable values dumped into the email too?

Below is the code I use to dump it into an email:

UtilityClass.SendEmail(shortNTID,
                       "admin@mydomain.com",
                       new string[] { "support@mydomain.com" },
                       "MyApplication error has occured for user: " +
                            shortNTID + " (Main).",
                       "Message: " + ex.Message.ToString() +
                       " Source: " + ex.Source.ToString() +
                       " Target Site: " + ex.TargetSite.ToString() +
                       " Stack Trace: " + ex.StackTrace.ToString());

And here is the result in the email:

Message: Specified cast is not valid. Source: MyApplication Target Site: Void FindFormAndActivate(MyApplication.MDIParentForm, System.String, System.Object) Stack Trace: at MyApplication.UtilityClass.FindFormAndActivate(MDIParentForm frmMDIParentForm, String formName, Object parameter)
at MyApplication.DashboardAlerts.NavigateToAssignment()
at MyApplication.DashboardAlerts.utAlerts_MouseClick(Object sender, MouseEventArgs e)
at System.Windows.Forms.Control.OnMouseClick(MouseEventArgs e)
at System.Windows.Forms.Control.WmMouseUp(Message& m, MouseButtons button, Int32 clicks)
at System.Windows.Forms.Control.WndProc(Message& m)
at System.Windows.Forms.Control.ControlNativeWindow.OnMessage(Message& m)
at System.Windows.Forms.Control.ControlNativeWindow.WndProc(Message& m)
at System.Windows.Forms.NativeWindow.Callback(IntPtr hWnd, Int32 msg, IntPtr wparam, IntPtr lparam)

EDIT

Some answers have suggested that I add the variable values myself to the email. How would I get those values though? This snippet of code that sends the email is not in the method that is failing. This is code that runs any time an exception occurs. If the exception isn’t handled and corrected, I let it bubble up to the top of the thread a la Application.ThreadException += new ThreadExceptionEventHandler(HandleError); and the HandleError method is the one that makes this email call. It has no idea what the variables or parameters were for the method that caused the exception.

  • 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-22T21:41:13+00:00Added an answer on May 22, 2026 at 9:41 pm

    Instead of trying to put them in the stack trace, just add them to the string you’re sending.

    UtilityClass.SendEmail(shortNTID,
                       "admin@mydomain.com",
                       new string[] { "support@mydomain.com" },
                       "MyApplication error has occured for user: " +
                            shortNTID + " (Main).",
                       "Message: " + ex.Message.ToString() +
                       " Source: " + ex.Source.ToString() +
                       " Target Site: " + ex.TargetSite.ToString() +
                       " Stack Trace: " + ex.StackTrace.ToString() +
                       " MyVar1 Value: " + MyVar1.ToString() +
                       " MyVar2 Value: " + MyVar2.ToString() +
                       " MyVar3 Value: " + MyVar3.ToString());
    

    Edit:

    Since the email is being sent outside the variables’ scope, you’re going to need to collect them when they’re in scope and add them to the exception being thrown. I’m afraid I don’t know much about the ThreadException object, but I’d create a custom exception that holds the values of those variables. You won’t be able to automagically add them to the stack trace; that’s not really what it’s for. So, off the top of my head:

    public class CustomException : Exception
    {
        public string MyVar1 { get; private set; }
        public string MyVar2 { get; private set; }
        public Exception OriginalException { get; private set; }
    
        public CustomException(Exception original, string myVar1, string myVar2)
        {
            MyVar1 = myVar1;
            MyVar2 = myVar2;
            OriginalException = original;
        }
    }
    

    Later, deep in your code:

    try
    {
        //code that might throw exceptions
    }
    catch (Exception e)
    {
        throw new CustomException(e, myVar1, myVar2);
    }
    

    The fact that you’re preserving the original exception by keeping it in the OriginalException property should (hopefully) also preserve the original stack trace.

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

Sidebar

Related Questions

I maintain an old PC-only application written in Delphi 7. Although Delphi has served
We have a web application that periodically sends out e-mails to users. At the
I maintain a ASP.NET web application that causes a user's network connection to reset
I maintain a VB6 application that stores its data (access files) in a subfolder
I maintain an old J2EE application that uses EJB's. What is involved in converting
I have an applet that talks with a Rails Application. I wish to maintain
I maintain a legacy application that runs on PHP/5.2.6 under Windows Server 2003 and
I work with an application that uses a large set of xml interfaces for
How would you maintain the legacy applications that: Has no unit tests have big
We currently maintain a suit of MFC applications that are fairly well designed, however

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.