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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 14, 20262026-05-14T18:49:28+00:00 2026-05-14T18:49:28+00:00

Getting back in to some C work. Many of my functions look like this:

  • 0

Getting back in to some C work.

Many of my functions look like this:

int err = do_something(arg1, arg2, arg3, &result);

With the intent the result gets populated by the function, and the return value is the status of the call.

The darkside is you get something naive like this:

int err = func1(...);
if (!err) {
    err = func2(...);
    if (!err) {
        err = func3(...);
    }
}
return err;

I could macro it I suppose:

#define ERR(x) if (!err) { err = (x) }
int err = 0;
ERR(func1(...));
ERR(func2(...));
ERR(func3(...));
return err;

But that only works if I’m chaining function calls, vs doing other work.

Obviously Java, C#, C++ have exceptions that work very well for these kinds of things.

I’m just curious what other folks do and how other folks do error handling in their C programs nowadays.

  • 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-14T18:49:29+00:00Added an answer on May 14, 2026 at 6:49 pm

    Two typical patterns:

    int major_func()
    {
        int err = 0;
    
        if (err = minor_func1()) return err;
        if (err = minor_func2()) return err;
        if (err = minor_func3()) return err;
    
        return 0;
    }
    
    int other_idea()
    {
        int err = minor_func1();
        if (!err)
            err = minor_func2();
        if (!err)
            err = minor_func3();
        return err;            
    }
    
    void main_func()
    {
        int err = major_func();
        if (err)
        {
            show_err();
            return;
        }
        happy_happy_joy_joy();
    
        err = other_idea();
        if (err)
        {
            show_err();
            return;
        }
        happy_happy_joy_joy();
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm having some trouble getting this to work, and I'm pretty close to concluding
Okay, this is probably a very basic question; but, I'm just getting back in
I've had some problems with handling forms and getting back to basics after an
I'm having some trouble getting unicode to work for git-bash (on windows 7). I
Afternoon, I am getting the following error, and cant work out why... Can some
So I'm working on getting some data with AJAX. All appears to work okay,
I'm getting back in to Cocoa development on the Mac after a long stint
gcc I am just getting back into c programming and I am just practicing
I'm getting back into web design after a several year break, so a lot
Would you please help me getting back the typename of the original object put

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.