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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 26, 20262026-05-26T15:00:55+00:00 2026-05-26T15:00:55+00:00

I have a particularly ugly piece of test code that is calling a number

  • 0

I have a particularly ugly piece of test code that is calling a number of methods on a hardware device to test it’s capabilities. It needs to gracefully fail in that if any of the methods throw an exception I wan’t the others to still be tested. Is there a more elegant way to represent a block of calls none of which I want to generate an exception?

 ...
 try
 {
     ExternalDevice.Call1();
 }
 catch (Exception e)
 {}
 try
 {
     ExternalDevice.Call2();
 }
 catch (Exception e)
 {}
 try
 {
     ExternalDevice.Call3(); 
 } catch (Exception e)
 {}
 //... many more like this
 ...

Thanks

  • 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-26T15:00:56+00:00Added an answer on May 26, 2026 at 3:00 pm

    I don’t recommend doing so, but here is a way:

    void Absorb(Action action)
    {
         try { action(); } catch { };
    }
    
    // ....
    Absorb(() => ExternalDevice.Call1());
    Absorb(() => ExternalDevice.Call2());
    Absorb(() => ExternalDevice.Call3());
    

    Note that, usually, you can use method groups to achieve simpler syntax:

    Absorb(ExternalDevice.Call1);
    Absorb(ExternalDevice.Call2);
    Absorb(ExternalDevice.Call3);
    

    To make it even shorter,

    void Absorb(params Action[] actions)
    {
         foreach (var action in actions) try { action(); } catch { };
    }
    
    So you can
    
    Absorb(ExternalDevice.Call1, ExternalDevice.Call2, ExternalDevice.Call3);
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have an ugly data entry task that needs automation. The problem is that
I have a project where I am taking some particularly ugly live HTML and
When I asked this previously I should have mentioned that it's particularly a light-weight
I have a general question about the way that database indexing works, particularly in
In the end, I have decided that this isn't a problem that I particularly
While debugging a piece of code that was exhausting the memory, I found a
I have a Django query and some Python code that I'm trying to optimize
I have a particularly difficult form that I am trying to click the search
I have a particularly slow query due to the vast amount of information being
More particularly - I have a window handle of another running application. This application

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.