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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 17, 20262026-06-17T05:54:08+00:00 2026-06-17T05:54:08+00:00

I am writing a C++ code that controls a special device that is the

  • 0

I am writing a C++ code that controls a special device that is the fusion of several SDKs. My code looks like

#define sdk1SafeCall(err) __sdk1SafeCall(err,__FILE__,__LINE__)

int errorcode = 0;
sdk1SafeCall(sdk1_InitializeDevice());
errorcode=sdk2_InitializeDevice();
errorcode=sdk3_InitializeDevice();

if (some_parameter)
{
    errorcode=sdk2_readDevice(true);
}
else
{
    errorcode=sdk3_writeDevice();
}
label again: errorcode=sdk1_readDevice();
if (error) goto again;

errorcode=close_everything();

Use parameters will rearrange the control flow. My current method uses something like cudaSafeCall to wrap the error codes and exit. What I don’t know how to do is where to store detailed explanations of these errors or how to recover from them (such as the goto example). At the end of the day the code looks really messy.

Edit

I do sometimes handle errors with a wrapper.

  • 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-17T05:54:09+00:00Added an answer on June 17, 2026 at 5:54 am

    Writing error-safe code is hard. In your pseudocode, you don’t actually deal with errors at all. errorcode will just have the result of “close_everything()” – which may have succeeded, even if everything else went wrong.

    The typical way to solve this sort of thing in C++ is to have an object for each “resource” (e.g. a “device”), and throw an exception if something goes wrong that you don’t expect to recover from. Wrap the whole function [or an outer set of functions] in a try/catch block.

    Of course, if “failure is normal” (e.g. you try to read from a network port, and you get a timeout because there was no data available, that’s not something you should throw an exception for). This should use a return-value.

    Note that using objects to handle resources requires careful design of the code and especially that your destructor does a good job of cleaning it is run after an exception. Make sure you don’t leave things behind if you throw an exception in a constructor – as that is how you get leaks.

    There are naturally a whole host of other solutions – after all, we’re talking programming, so there’s always at least 11 different ways to solve something.

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

Sidebar

Related Questions

Currently I'm writing code to make variable sized tables with asp:controls in them that
I am writing code that will spawn two thread and then wait for them
I am writing code that catches this OutOfMemoryException and throws a new, more intuitive
I'm using c#. In many cases I'm writing code that can benefit from a
I am a very proficient C# developer, but need to start writing code that
I'm writing some code that will take a screenshot of another application, given its'
I am writing some code that will go through a file, edit it as
I'm writing a code that uses bitboards. since iterating on all bits of a
I'm writing some code that has a lot of substitution. There's a list<char> productions
I am writing some code that connects to a website, and using C#, and

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.