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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 12, 20262026-06-12T06:24:47+00:00 2026-06-12T06:24:47+00:00

catch(Exception ex) { //do what you want here //When type of exception is System.Web.Services.Protocols.SoapException

  • 0
catch(Exception ex)
{
    //do what you want here

    //When type of exception is System.Web.Services.Protocols.SoapException
    //if (ex.Code.Name.Equals("Client"))
    //{
    //      msg = "service's function not exist";
    //}
    //else if (ex.Code.Name.Equals("Server"))
    //{
    //     msg = "function error"
    //}
    //else
    //{
    //     msg = "unknown";
    //}
    //MessageBox.Show(msg, "error", MessageBoxButtons.OK);

**But ex is not System.Web.Services.Protocols.SoapException so I cannot call ex.Code.Name.Equals("Client")**


//When System.Net.WebException
//switch (ex.Status)
//{
//   case System.Net.WebExceptionStatus.ConnectFailure:
//              do some thing
                break;
//   case System.Net.WebExceptionStatus.Timeout:
                //do some thing
                break;
//    case System.Net.WebExceptionStatus.ProtocolError:
            switch (((System.Net.HttpWebResponse)ex.Response).StatusCode)
            {
                  case System.Net.HttpStatusCode.NotFound:
                        //do some thing
                        break;
                    case System.Net.HttpStatusCode.ServiceUnavailable:
                        //do some thing
                        break;
                    case System.Net.HttpStatusCode.Unauthorized:
                        //do some thing
                        break;
                    default:
                        //do some thing
                        break;
                }
                break;
            default:
                //do some thing
                break;
        }
}

But Exception is not System.Net.WebException. So cannot call ex.Status

My problem:

I have a Smartclient software include WindowsForm as client and a webservice as server.
Client and Server both are n-tiers application
I have tested and found that has any problem when call service from Client

  1. in app.config: service’s path wrrong . I catch System.NotSupportedException
  2. Or when the server cannot connect: System.Net.WebExceptionStatus
  3. Server’s webconfig is wrong : System.InvalidOperationException
  4. Service throws an exception: System.Web.Services.Protocols.SoapException
    …

My Idea

I call the Exception that as representative of all other exception types is representativeAlException

I have namespace : Common and two classese representativeAlException.cs and BusinessExceptionHandler.cs

Make a common function with a param as (representativeAlException ex)

            try
            {
                Err_LogCheck.Service1.Service1 service = new Err_LogCheck.Service1.Service1();
                return service.getDeviceByZero(ZERO);
            }
            catch (Common.representativeAlException ex)
            {
                Common.BusinessExceptionHandler.ProcessException(ex);
            }

What I want to do

Where the service is called. Only one catch block can handler for all type of Exception

in ProcessException(representativeAlException ex) function

switch (ex)
{
case System.InvalidOperationException:
 //Do some thing
 break;
case System.NotSupportedException:
 //Do some thing
 break;
case System.Web.Services.Protocols.SoapException:
 //do some thing
 break;
...
...
  • 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-06-12T06:24:49+00:00Added an answer on June 12, 2026 at 6:24 am

    To handle all exception, use Exception class.

    try
    {
    
    }
    catch(Exception ex)
    {
         switch (ex.GetType().ToString())
         {
             case "System.InvalidOperationException":
                  //cast ex to specific type of exception to use it's properties
                  ((InvalidOperationException)ex).SomeMethod();
             break;
             case "System.NotSupportedException":
                 ((System.NotSupportedException)ex).AnotherMethod();
             break;
             case "System.Web.Services.Protocols.SoapException":
                 ((System.Web.Services.Protocols.SoapException)ex).OtherMethod();
             break;
         }
    
    }
    

    Why can’t you just use multiple catch block anyway?

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

Sidebar

Related Questions

This is my below code and I want to catch the exception if any
I want a way to check in my catch {} clause if the exception
try { // Code } catch (Exception ex) { Logger.Log(Message, ex); throw; } In
Hi guys i catch exception: java.lang.IndexOutOfBoundsException: Index: 1, Size: 0 Code look like this:
I want to retrieve token via Account Manager classes. Here is sample code that
I want to catch exception of a thread in doInBackground and print the error
I want to catch exceptions thrown by classes implementing Processor interface. In aspect I
I'd like to catch exception which occurs when somebody gives not a number value
Why is the catch(Exception) almost always a bad Idea?
Possible Duplicate: catch exception by pointer in C++ I always catch exceptions by value.

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.