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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 24, 20262026-05-24T05:00:20+00:00 2026-05-24T05:00:20+00:00

I have recently started using boost::exception. Now I would like to use boost::errinfo_nested_exception to

  • 0

I have recently started using boost::exception. Now I would like to use boost::errinfo_nested_exception to print information about the cause of the error. The problem is I can’t figure out how to get information from the cause. I have tried the following with no success:

#include <iostream>
#include <boost/exception/all.hpp>

struct myex : public virtual boost::exception {};

int main()
{
   myex cause;
   cause << boost::errinfo_file_name("causefile.cpp");

   try {
      myex ex;
      ex << boost::errinfo_nested_exception(boost::copy_exception(cause));
      throw ex;
   }
   catch (myex& e) {
      // Here I would like to extract file name from cause and print
      // it in a nice way, but I cant figure out what to do with a
      // boost::exception_ptr.
      const boost::exception_ptr* c = 
         boost::get_error_info<boost::errinfo_nested_exception>(e);

      // I cant do this:  
      // const std::string* file = boost::get_error_info<boost::errinfo_file_name>(*c);

      // Nor this: 
      // const std::string* file = boost::get_error_info<boost::errinfo_file_name>(**c);

      // This works fine and the nested exception is there, but that's not what I want.
      std::cout << boost::diagnostic_information(e) << std::endl;
   }

   return 0;
}
  • 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-24T05:00:21+00:00Added an answer on May 24, 2026 at 5:00 am

    You need to rethrow the nested exception and examine that:

    const boost::exception_ptr* c = 
        boost::get_error_info<boost::errinfo_nested_exception>(e);
    if(c) try {
        boost::rethrow_exception(*c);
    } catch(boost::exception const& e) { // or a type derived from it
        const std::string* file = boost::get_error_info<boost::errinfo_file_name>(e);
        // ...
    } catch(...) {
        // presumably you don't want the exception to escape if it is
        // not derived from boost::exception
    }
    

    I personally use a get_error_info wrapper that returns the result of boost::get_error_info<some_error_info>(e), or if nothing is found the result of get_error_info<some_error_info>(nested) (recursive call here) or 0 if there is no nested exception (or it is not error_info-enabled).

    Alternatively/as a complement, you can factor the checking code above (the different catch clauses) in a function:

    std::string const* // or return a tuple of what you examined etc.
    examine_exception()
    {
        try {
            throw; // precondition: an exception is active
        } catch(boost::exception const& e) {
            // as above
            return ...;
        }
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have recently started using Vim as my text editor and am currently working
I have recently started looking into Google Charts API for possible use within the
I've been a web developer for some time now, and have recently started learning
I have recently started using VirtualBox to get my Linux environment rather than fully
I have recently started playing with databases, trying to teach myself using examples. I
I have recently started to learn lisp, and have mainly bin using clisp and
I recently started using R language and now i am using R for most
I have recently started having problems with TortoiseCVS, or more specifically with plink, the
I have recently started working on a very large C++ project that, after completing
I have recently started learning F#, and this is the first time I've ever

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.