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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 14, 20262026-05-14T04:02:40+00:00 2026-05-14T04:02:40+00:00

I have a Result object that lets me pass around a List of event

  • 0

I have a Result object that lets me pass around a List of event messages and I can check whether an action was successful or not.

I’ve realized I’ve written this code in alot of places

Result result;

try
{
    //Do Something 
    ...

    //New result is automatically a success for not having any errors in it
    result = new Result(); 
}
catch (Exception exception)
{
    //Extension method that returns a Result from the exception
    result = exception.ToResult();
}

if(result.Success) ....

What I’m considering is replacing this usage with

public static Result CatchException(Action action)
{
    try
    {
        action();
        return new Result();
    }
    catch (Exception exception)
    {
        return exception.ToResult();
    }
}

And then use it like

var result = Result.CatchException(() => _model.Save(something));

Does anyone feel there’s anything wrong with this or that I’m trading reusability for obscurity?

Edit: The reason I am trapping all exceptions is I use this code inside of my ViewPresenter classes at any point I interact with my model since if I get an unhandled exception I’d rather display the actual error to the user (internal app) as opposed to just redirecting them the generic error page.

  • 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-14T04:02:40+00:00Added an answer on May 14, 2026 at 4:02 am

    I don’t think there is anything wrong with using a functional approach, and passing in a lambda. That is perfectly valid.

    That being said, I’d question your use in this specific scenario. Trapping all exceptions into a general purpose “Result” class seems dangerous. Ideally, you should be catching exceptions which you can handle correctly – not every possible exception and continuing.

    That being said, if you really want to do this, I have a couple of suggestions for you:

    1) I’d make a static, immutable result for success, and just do:

    result = result.Success;
    

    This avoids generating a new “success” each time you succeed, which hopefully is the most common option.

    2) I’d probably avoid the extension method, and do:

    result = new Result(exception);
    

    This will be much more clear and obvious in intent, and there’s really no reason to do an extension method in this case…

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

Sidebar

Related Questions

I have a action result method i would like to run. How can i
I have array result like this: Array ( [0] => stdClass Object ( [id_global_info]
i have this JSON object: {error:null, result:[{id:1234567890, count:1, recipients: [u3848, u8958, u7477474 ], dateCreated:2012-06-13T09:13:45.989Z
I have a result of a db query in java.sql.ResultSet that needs to be
Let's imagine that I have a result of evaluating XPath expression //node/@*. MSXML6 returns
I have a collection of PHP classes that can be instantiated traditionally using constructors.
I have a class that contains a member object. I would like to call
Lets say I have a string that represents a date that looks like this:
I have a list box that show some positions of (X,Y) in each row.
lets assume that we have two operation contracts defined on wcf service, sync and

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.