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

  • Home
  • SEARCH
  • 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 8092137
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 5, 20262026-06-05T20:13:25+00:00 2026-06-05T20:13:25+00:00

I have multiple calls to methods in a 3rd party library. These methods have

  • 0

I have multiple calls to methods in a 3rd party library.
These methods have a wide variety of different signatures / parameter combinations.

There are specific errors that the 3rd party library generates that I would like to catch and handle, and since the resolution is the same I would like it to take place in a single handler.

So I want to be able to have a method that essentially takes in as parameters a function (delegate) and its arguments, and invokes it inside some try/catch logic.

I don’t know if its just not possible or I’m not getting the syntax right, but I can’t figure out how to handle the fact that the signature for each method being passed in is different.

Any suggestions?

  • 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-06-05T20:13:26+00:00Added an answer on June 5, 2026 at 8:13 pm

    You could use Action and Func<T> to wrap the methods, and closures to pass arguments.

    public TResult CallMethod<TResult>(Func<ThirdPartyClass, TResult> func)
    {
        try
        {
            return func(this.wrappedObject);
        }
        catch(ThirdPartyException e)
        {
            // Handle
        }
    }
    
    public void CallMethod(Action<ThirdPartyClass> method)
    {
        this.CallMethod(() => { method(this.WrappedObject); return 0; });
    }
    

    You could then use this via:

    var result = wrapper.CallMethod(thirdParty => thirdParty.Foo(bar, baz));
    

    Edit: The above was assuming you were wrapping an instance of the third party library. Given (from your comments) that these are static methods, you can just use:

    public static TResult CallMethod<TResult>(Func<TResult> func)
    {
        try
        {
            return func();
        }
        catch(ThirdPartyException e)
        {
            // Handle
        }
    }
    
    public static void CallMethod(Action method)
    {
        CallMethod(() => { method(); return 0; });
    }
    

    And then call via:

    var result = Wrapper.CallMethod(() => ThirdParty.Foo(bar, baz));
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I was developing a swing application which calls multiple methods & initializes different classes.
Under JBoss 4.0.1SP1, I have a servlet that makes multiple, concurrent calls to web
There are many java standard and 3rd party libraries that in their public API,
I have a simple x86-targeting .NET 3.5 console program that calls methods on COM
I have multiple calls to many RESTful services. I translate to PHP using native
I currently have a web based application which strictly relies on a 3rd party
I have methods with more than one parameter that are guarded against bad input
I am using EF4/RIA combo in a Silverlight application. I have multiple service methods
I want to send multiple asynchronous calls to different web services with silverlight and
I am new to WCF. I have multiple methods throwing the same exceptions for

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.