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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 24, 20262026-05-24T06:04:08+00:00 2026-05-24T06:04:08+00:00

I need your advice. My source application become very.. expanded. And I have a

  • 0

I need your advice. My source application become very.. expanded. And I have a little problem dealing with errors, exceptions etc..

For example I have “DatabaseProvider” class where are methods to contact with db. I have to deal with standard exceptions, invalid data form database (for example wrong email format), errors returned from database. All that stuff I need to return to the function which called DatabaseProvider’s method, so that method will log this exception or error, and still working. So I can’t throw exception.

And if that were not enough, I have to return (from DatabaseProvider) a value in most of cases or object or list of objects.

So I thought, maybe create a class “Response”. And object of that class will be returned from every method in my app.

Sth like that:

public class Response
{
    public bool Error { get; set; }
    public string ErrorMessage { get; set; }        
    public bool DatabaseError { get; set; }
    public string DatabaseMessage { get; set; }

    public Exception ex { get; set; }
}

But how to return (for example) a list of self design objects in the same time?

Using “out” parameters are the solution? What is the best way (best practice)? I was searching about that, but all i found was how to deal with exceptions (only)..

  • 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-24T06:04:10+00:00Added an answer on May 24, 2026 at 6:04 am

    I would’ve recommended implementing a custom Exception which you can throw and catch, rather than returning this information, since it seems very error-specific.

    However if you always want to attach certain meta information to returned results, you might implement a small vehicle class to wrap the results while carrying meta information:

    abstract class ResultWrapper
    {
        //meta info, such as error references/properties/flags/statistics
    
        public ResultWrapper([meta info])
        {
            //set meta info
        }
    }
    
    class ResultList<T> : ResultWrapper
    {
        public readonly List<T> resultList;
    
        //constructor for resultList, plus meta information for parent
        public ResultList(List<T> resultList, [additional args for meta info]) : base([meta info])
        {
            this.resultList = resultList;
        }
    }
    
    class SingleResult<T> : ResultWrapper
    {
        public readonly T result;
    
        //constructor similar to above
    }
    

    Edit: Based on your comments, you should definitely go with custom Exceptions which you can throw (possible wrapping cause Exceptions). As Petar said, these can be caught within the loop and processed there without halting execution of subsequent tasks. The language supports exception handling for good reasons – I would make use of it.

    Also, fyi in your pattern:

    public bool Error { get; set; }
    public string ErrorMessage { get; set; }
    

    there is no need for the bool. Just check for non-null on the error message/reference field

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

Sidebar

Related Questions

I am developing a WPF application, and I need your advice. I have to
I need your advice. We have an already working web resource management application, we
I need your advice guys. I am developing a web browser application for mobile
Good morning, experts I need your advice. Let's say we have user , profile
I am just studying so I need your advice. I have found a code
I need your advice about framework selection (Java vs Mono) for a new large
I need your advice on this piece of code: the table fields options[0], options[1]
I need your expertise once again. I have a java class that searches a
I need your help, For example I have a decimal type variable and I
I really need your help in my issue very quickly and it's too close

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.