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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 25, 20262026-05-25T21:25:02+00:00 2026-05-25T21:25:02+00:00

I have my own wcf service class which should as result return string with

  • 0

I have my own wcf service class which should as result return string with “Everything Save Saccesfully” if ok save data. Otherwise I need to return in this string exception.

string SaveData(Stream stream)
{
  string error = "";
  try
  {

  //do saving data
   error+="Everything Save Saccefully";
   return error;
  }
  catch(Exception ex)
  {
   throw ex;
  }
  finally
  { 
  }
}

It is possible to catch errors occurs in try block and return it in error variable ?

  • 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-25T21:25:02+00:00Added an answer on May 25, 2026 at 9:25 pm

    Normally I would do as suggested by Jon, but if you really don’t want to allow any exceptions to bubble up from your service you could encapsulate your success and (any) failure error information in a class structure like this

    public class ErrorInfo
    {
        public string Message {get; set;}
    
        // TODO: Maybe add in other information about the error?
    }
    
    public class SaveResult
    {
        public bool Success { get; set; }
    
        /// <summary>
        /// Set to contain error information if Success = false
        /// </summary>
        public ErrorInfo ErrorInfo { get; set; }
    }
    

    And then…

    public SaveResult SaveData(Stream stream)
    {
        SaveResult saveResult = new SaveResult();
    
        string error = "";
        try
        {
            //do saving data
            saveResult.Success = true;
        }
        catch (Exception ex)
        {
            saveResult.ErrorInfo = new ErrorInfo { Message = ex.Message };
        }
    }
    

    The downside of this approach is that your caller must check the Success value after calling SaveData. Failure to do so can result in a bug in your code that will only manifest itself if the save fails.

    Alternatively, if you don’t handle the exception you get to benefit from one of the useful things about structured exception handling: If the caller forgets to explicitly handle any exception then it will bubble up the call stack and either crash the app or get caught by some higher-level error handling code.

    Not necessarily ideal, but generally better than your code silently assuming that something succeeded, when in fact it didn’t.

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

Sidebar

Related Questions

I have a WCF service which all operations return type is OperationStatus: [DataContract] public
I'm trying to hide window after its startup. I have own window-class which is
I have several service contracts exposed over WCF, which use multiple datacontracts. The service
I have a RESTful WCF service that can return XML, JSON, or JSONP, depending
I have a WCF service setup with my own UserNamePasswordValidator. When authentication fails in
I have my own custom Content Provider that loads a database which contains the
We have our own custom calendar in our portal which is developed in Java.
I have a VERY complex service host which consists of multiple DUPLEX services here.
I'm trying to host a WCF Service inside a Windows Service which I am
We have a WCF service that exposes a Customer type, i.e.: [DataContract(Name = CustomerData,

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.