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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 28, 20262026-05-28T01:52:48+00:00 2026-05-28T01:52:48+00:00

Starting to use the googletest ASSERT_THROW clause, it seems that ‘sometimes’ the base type

  • 0

Starting to use the googletest ASSERT_THROW clause, it seems that ‘sometimes’ the base type of the thrown exception is handled. I reduced the relevant code section to this:

// myexception.h
struct myexception : public std::logic_error {
   myexception(const char* what):std::logic_error(what){}
};
void throwMy();

// myexception.cpp
void throwMy(){ throw myexception(NULL); }

This is my test code:

//
void localThrowMy(){ throw myexception(""); }

// test code, based upon the ASSERT_THROW macro
try {
  throwMy();        // outputs "logic_error"
  //localThrowMy(); // would output "what I expected"
}
catch( myexception & ) { cout << "what I expected"; }
catch( std::logic_error & ) { cout << "logic_error"; } // my addition
catch(...) { cout << "mmmh."; }

The strange thing is: if I declare the throwMy function in the same compilation unit as the test code, “what I expected” is output. If it’s in another unit, the test outputs “logic_error.”.

  • g++ –version: (Debian 4.4.5-8) 4.4.5
  • ld –version: (GNU Binutils for Debian) 2.20.1-system.20100303

Is this code correct? Could the linker be in error here?

  • 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-28T01:52:48+00:00Added an answer on May 28, 2026 at 1:52 am

    Mea Culpa.

    Once again, select wasn’t broken.

    The logic_error was thrown within the std::string constructor: “basic_string::_S_construct NULL not valid”. I falsely deduced that there was a problem with the inheritance; it was a plain case of pebkac.

    Actually, I didn’t know. But you can’t pass a null pointer into the std::string constructor.

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

Sidebar

Related Questions

I'm just starting to use the Enterprise Library Exception Handling block. It seems a
Starting to use Nhibernate for persistency being seduced by the promise that it respects
I'm just starting to use git-deploy instead of capistrano, the problem is though that
We are starting to use a Scrum process for development. We have a nice
I am just starting to use Subversion with Tortoise SVN client for one of
I'm just starting to use Django for a personal project. What are the pros
I'm starting to use ASP.NET Ajax. Following Eric Pascarello's recommendations, I always operate under
I am starting to use the jquery $.ajax() but I can't get back what
I am starting to use some Java code which was written by someone else.
I'm starting to use Moq and I cannot figure out how to test the

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.