1
Answer

Wrapped Exception Function

rajinarayan

rajinarayan

19y
3k
1
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");
   }
   
   }
Answers (1)
0
Vulpes
NA 98.3k 1.5m 12y
Try this:

using System;

class Test
{
  static void Main()
  {
    string[] urls =
    {
      @"http://g-ecx.images-amazon.com", 
      @"http://z-ecx.images-amazon.com", 
      @"http://ecx.images-amazon.com",
      @"http://completion.amazon.com", 
      @"http://client-log.amazon.com", 
      @"http://www.amazon.com/184-8984226-0489751",
      @"http://www.amazon.com/access",                
      @"http://www.amazon.com/gp/product/B0083PWAPW/ref=kin_dev_gw_dual_t/184-898422604...",  
      @"http://www.amazon.com/gp/product/B007OZNZG0/ref=kin_dev_gw_dual_c/184-8984226-04...",                     
      @"http://www.amazon.com/gp/prime/signup/videos/ref=nav_menu_video_redirect_combine...", 
      @"http://www.amazon.com/gp/prime/signup/videos/ref=nav_menu_video_pic_redirect_com...", 
      @"http://www.amazon.com/gp/prime/signup/videos/ref=nav_menu_shipping_redirect_comb...", 
      @"http://www.amazon.com/gp/prime/signup/videos/ref=nav_menu_shipping_pic_redirect_..."
    };  

    foreach(string url in urls)
    { 
      Uri uri = new Uri(url);
      string[] items = uri.Host.Split('.');
      string domain = "";
      if (items.Length == 3)
      {
         domain = items[1];
      }
      else if (items.Length == 2)
      {
         domain = items[0];
      }
      if (domain.IndexOf('-') > -1)
      {
          domain = domain.Substring(domain.LastIndexOf('-') + 1);
      }

      Console.WriteLine(domain); 
    }

    Console.ReadKey();
  }
}