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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 19, 20262026-05-19T16:28:50+00:00 2026-05-19T16:28:50+00:00

I am fully aware that what I am about to ask is not good

  • 0

I am fully aware that what I am about to ask is not good practice… but:

Let’s say I have a class containing a function that I want to always return a value, but store any exceptions that might occur for later processing. Something Like:

public Exception _error { get; set; }

public bool IsValid()
{
    try
    {
        //do something here to cause exception                

        return true;
    }
    catch (Exception ex)
    {
        _error = ex;
        return false;
    }
}

Now that I have stored the exception, is it at all possible to throw the exception from an outside method while maintaining both the original stack trace and exception type?

throw _error; //lose stack trace

throw new Exception("", _error) //lose type

Thanks for looking or answering.

EDIT:

Thanks to some additional points, I realize that the below idea only takes away information and doesn’t really add or simplify the situation. Thanks again to everyone.


After pondering Pieter’s answer and comments, I’m now wondering if making a wrapper Exception class like the below could be a partial solution. This overrides as much of the exception as possible to make the New exception look like its innerexception, including the stacktrace.. dirty I know, but interesting:

public class ExceptionWrapper : Exception
{
    private Exception _innerException;

    public ExceptionWrapper(Exception ex) : base("", ex)
    {
        _innerException = ex;
        this.Source = ex.Source;
        this.HelpLink = ex.HelpLink;
    }

    public override string StackTrace
    {
        get
        {
            return _innerException.StackTrace;
        }
    }

    public override System.Collections.IDictionary Data
    {
        get
        {
            return _innerException.Data;
        }
    }

    public override string Message
    {
        get
        {
            return _innerException.Message;
        }
    }

    public new Exception InnerException
    {
        get
        {
            return _innerException.InnerException;
        }
    }
}

  • 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-19T16:28:50+00:00Added an answer on May 19, 2026 at 4:28 pm

    No, this is not possible.

    However, you normally solve this is by wrapping the exception in a new exception:

    throw new MyException("Wrapper", _error);
    

    This does maintain the stack trace of _error, but you do get a new exception. Your solution in your second example is the correct way of handling these cases.

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

Sidebar

Related Questions

I am aware that System.Threading.Timer exists, but I already have a Thread. This thread
Disclaimer Yes, I am fully aware that what I am asking about is totally
Being resonably new to using GTK+, im not fully aware of all its functionality.
I fully appreciate the atomicity that the Threading.Interlocked class provides; I don't understand, though,
Say I have a class, something like the following; class MyClass { public: MyClass();
Currently we have no SVN/Git/Mercurial setup at work. We're fully aware it's a bad
I am aware -that in Java- int is 4 bytes. But I wish to
I have three models that i'd like to perform a simple search across: class
I'm fully aware of the impact of flagging a thread as a daemon thread
I am fully prepared to admit that I am missing something simple here. I

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.