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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 29, 20262026-05-29T10:54:23+00:00 2026-05-29T10:54:23+00:00

I have a callback function which is bound to a boost::asio::deadline_timer . Now the

  • 0

I have a callback function which is bound to a boost::asio::deadline_timer. Now the function is called when the timer is cancelled or it expires. Since I need to distinguish between this two cases I need to check the passed Error code. The basic code would be like this:

void CameraCommand::handleTimeout(const boost::system::error_code& error)
{
    std::cout << "\nError: " << error.message() << "\n";
    return;
}

Now when the Handler is called because the timer expired the error code is Success, when the timer is cancelled the error code is Operation canceled.

Now my question would be, how to appropriately check what happened?

Suggestion 1:

if( error.message() == "Success" )
{
     // Timer expired
}
else
{
     // Timer cancelled
}

Suggestion 2:

if( error.value() == 0 )
{
     // Timer expired
}
else
{
     // Timer cancelled
}

Now my question is – is there any way to compare the error byitself and not by value or by string? Something like ( this is made up now )

if ( error == boost::system::error::types::success )

Because what I don’t like about the first suggestion is that I need to create a string just for check, which is kinda unnecessary in my opinion. The second way has the disadvantge that I need to look up all the error codes if I want to check for something other?
So are there any enums or ways to check for the error or do I have one of the two suggested ways?

  • 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-29T10:54:24+00:00Added an answer on May 29, 2026 at 10:54 am

    Looking at the documentation, you can use the enum values:

    switch( error.value() )
    {
        case boost::system::errc::success:
        {
        }
        break;
    
        case boost::system::errc::operation_canceled:
        {
          // Timer cancelled
        }
        break;
    
        default:
        {
           // Assert unexpected case
        }
        break;
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a js function which has, until now, always been the callback for
I have a callback function which has the parameter const unsigned char *pData .
I have a function which takes a callback function. How can I set the
How do i debug my callback scripts? I have a deal_management function which does
I have a static callback function which is supposed to set an NSString and
In C I have a function which registers a callback and a state object
Here I create a class in JAVA in which I have function (callback) which
I have a callback function within an ASP.NET Web Forms application which I am
My question is about Javascript. I have a Callback function which receives a Position
Eg. I have following delegate method I want to use as a callback function

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.