FaultException() exception thrown by the service is not caught by the client catch(FaultException)

Also posted here:-
Ok, I know I am missing something here. I have the following operation contract:
 
    public double DivideByZero(int x, int y)
    {                  
        if (y == 0)
        {
            throw new FaultException<ArgumentException>
              (new ArgumentException("Just some dummy exception")
              ,new FaultReason("some very bogus reason"), new FaultCode("007"));
        }
        return x / y;
    }
And following is taken from the client:-
      Console.WriteLine("Enter the x value");
      string x = Console.ReadLine();
      Console.WriteLine("Enter the Y value");
      string y = Console.ReadLine();
      try
      {
          double val = client.DivideByZero(Convert.ToInt32(x), Convert.ToInt32(y));
          Console.WriteLine("The result is " + val.ToString());
      }
      catch(FaultException<ArgumentException> exp) 
      {
          Console.WriteLine("An ArgumentException was thrown by the service "+ exp.ToString());   
      }
      catch (Exception exp)
      {
          Console.WriteLine(exp.ToString());
      }
In the above case  catch(FaultException<ArgumentException> exp) (the first catch block with ArgumentException in the client code) block does not get executed. However, when I remove ArgumentException to have catch(FaultException exp), the same catch block gets executed. I am not sure about this as I am throwing FaultException<ArgumentException> from my operation contract. Am I missing anything here.
 
NOTE:-
 If you have a custom exception class and use that to throw and catch, It does work. Not sure why it wont work (serialize) with ArgumentException.
Advertisements
  1. Leave a comment

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s

Random Thoughts

The World as I see it

Simple Programmer

Making The Complex Simple

Ionic Solutions

Random thoughts on software construction, design patterns and optimization.

Long (Way) Off

A tragic's view from the cricket hinterlands

%d bloggers like this: