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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 25, 20262026-05-25T16:31:32+00:00 2026-05-25T16:31:32+00:00

In general I want to make a code that makes a call an Execute

  • 0

In general I want to make a code that makes a call an Execute function of a class which may throw an exception. My question is should I setup the class and should I extract the values from it within the try/catch or out side?

Option A:

neededValue V;

try
{
    MyClass C = new MyClass();
    C.SomeParam = XXX;
    C.Execute();
    V = C.SomeParam2;
}
catch
{
    //Clean up...
    //Log...
    //Throw new exception
}

Option B:

neededValue V;
MyClass C = new MyClass();
C.SomeParam = XXX;

try
{
    C.Execute();
}
catch
{
    //Clean up...
    //Log...
    //Throw new exception
}

V = C.SomeParam2;

I know both will work, but which is nicer and easiest to read?

  • 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-25T16:31:34+00:00Added an answer on May 25, 2026 at 4:31 pm

    I would say option B is easier to read and more practical because you will know later that the Execute can throw and Exception.

    They are not the same, in option B if you handle the exception then your B variable will be set too and not only if your Execute succeeds.

    And you should always specify with the catch block what kind of exception you are catching and so you can handle it and/or Log it correctly.

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

Sidebar

Related Questions

I want to make a general error handling package that should be called from
I want to make a call to a webservice of which I only have
The general rule is that I want to say, T has a method with
I have one very general object that I want to map to a destination
General Python Question I'm importing a Python library (call it animals.py) with the following
I'm testing some legacy code that extends the default php exception object. This code
Just a very general question, that not only applies to this example. Let's say
In general I want to disable as little code as possible, and I want
In general, if you have a class that inherits from a Thread class, and
Edit: There was some confusion, but I want to ask a general question about

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.