Skip to content

Wrapped Exception Function

rajinarayan

Asked Nov 23, 2005, 9:40 PM EST1 answer
Share
LinkedInX
Hi,

I am working on wrapping an exception over another.

I need a function to which i will be passing my friendly exception message and the exception object.
In that function i should be able to get the wrapped exception details and the parent exception details.

I am breaking my head with this for the past 2 days.

Help needed!!


private void button1_Click(object sender, System.EventArgs e)
   {
   try
   {
     try
     {
     
     int i = 7;
     int j = 0;

     int k = i/j;

     }
     catch (Exception ex)
     {
     //throw new Exception("The wrapped exception message",ex);    
         }
   }
   catch(Exception ex)
   {
     
     MessageBox.Show("Error in Demo function");
   }
   
   }

1 Answer

Know the answer? Post it. Somebody with the same question will find it here.

  • 0

    Make your own exception class.

    class MyException : Exception
    {
        public MyException(string in_szMessage, Exception in_oParent)
        {
            m_szMessage = in_szMessage;
            m_oParentEx = in_oParent;
        }

        public string m_szMessage = null;
        public Exception m_oParentEx = null;
    }

    private void m_butMyButton_Click(object sender, EventArgs e)
    {
        try
        {
            try
            {
                int i = 7;
                int j = 0;
                int k = i / j;
            }

            catch (Exception ex)
            {
                throw new MyException("The wrapped exception message",ex);
            }
        }

        catch (MyException ex)
        {
            DoWhateverYouWantWith(ex.m_szMessage);
            DoWhateverYouWantWith(ex.m_oParentEx);
        }

    0