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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 27, 20262026-05-27T18:48:56+00:00 2026-05-27T18:48:56+00:00

I have a class that has about 200+ methods, each of these methods makes

  • 0

I have a class that has about 200+ methods, each of these methods makes a call into the database, or a network resource.

Ideally, I would like to wrap each call in a try/catch, to catch any of the common network or SQL exceptions, and give the user the opportunity to try again (if appropriate). However, to add this code to each call would be very time consuming, and bloated as far as the code is concerned.

I’ve thought about wrapping each of the method calls in another method, creating a delegate, and wrapping the delegate code in the try/catch.. something like this…

(Ignore the syntax.. it’s just a conceptual example)

bool CallUpdatePassenger(int PassengerId,string PassengerName,string PhoneNumber)
{
    Delegate del= Delegate.CreateDelegate(typeof(UpdatePassengerDelegate), typeof(IPassengerServices).GetMethod("RemoteUpdatePassenger"));
    bool Res=(bool)CallDelegate(del,PassengerName,PhoneNumber);
}
object CallDelegate(Delegate del,params object[] args)
{
    object Result=null;
    try
    {
        Result=del.DynamicInvoke(args);
    }
    catch (Some.Timeout.Error.Or.Whatever te)
    {
        // take some action.. maybe retry etc.. 
    }
    return Result;
}

Maybe there’s a more pracitcal way of doing this ?

The code is automatically generated (by a tool which I wrote) I can quite easily include something like the above, but I want to avoid writing the above code for every method call.

Also, if I do something like the above, I can time methods, and log method calls etc. It just seems a bit clumsy (and not strongly typed).

Thanks
Rich.

  • 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-27T18:48:57+00:00Added an answer on May 27, 2026 at 6:48 pm

    You should be able to just do something like:

    T Execute<T>(Func<T> func) {
        try {
            return func();
        } catch (...) {
            ...
        }
    }
    bool CallUpdatePassenger(some args here) {
        return Execute( () => realObj.RemoteUpdatePassenger(some args here));
    }
    

    alternatively, you could use meta-programming to write a dynamic “decorator” for the underlying methods on the fly… but unless you are familiar with ILGenerator etc probably best not to – it is a fairly advanced topic.

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

Sidebar

Related Questions

I have a class that has about 20-some methods in it. Each one does
I have a c# class that has 20+ string properties. I set about a
I have a question about copy constructors/copying objects. I have a class that has
I'm puzzled about iOS memory management. I have a class that has a member
I have a class that has to take product information from one system's database
I have a class that has purely static Methods and properties. I am calling
I have a class that has a Generic type G In my class model
I have a class that has some properties. And I want something that calculates
I have a class that has a vector of another class objects as a
I have a class that has an inner struct/class (I have decided which yet,

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.