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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 4, 20262026-06-04T01:50:13+00:00 2026-06-04T01:50:13+00:00

I just noticed my code repeats this structure a lot: if( someErrorHappened ){ string

  • 0

I just noticed my code repeats this structure a lot:

if( someErrorHappened ){
        string errorMsg = "Falcon Punch!";
        ::GetErrorLoggerInstance()->Log( LOG_TYPE_ERROR, "class", "method", errorMsg );
        throw SomeCustomException( errorMsg );
}

I figured I could write a template function so that I could replace all those with a one-liner like this:

LogAndThrowIfError<SomeCustomException>( someErrorHappened, "class", "method", "Falcon Punch!" );

I can do that just fine with my basic templates knowledge. My question is, can I use Boost to ensure that a compile error ensues if the template argument is a class which does not inherit from a specific class? (i.e. I only want to let this function be used for my custom exceptions). Kinda like C#’s where keyword for generics.

This might seem farfetched, but I need to enforce this because our application has managed and unmanaged code, and our custom native exceptions are mapped to custom managed exceptions, that’s why this should only be used with our exceptions.

I’m working in Visual Studio 2010, so I don’t have all the fancy C++11 stuff, just some of it (move semantics being the juiciest).

  • 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-04T01:50:15+00:00Added an answer on June 4, 2026 at 1:50 am

    Try with

     BOOST_STATIC_ASSERT(( boost::type_traits::is_base_of< ExceptionBaseClass, T >::value ));
    

    It internally does the same check that @Zolyomi posted in his answer.

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

Sidebar

Related Questions

I was just writing some quick code and noticed this complier error Using the
I've just noticed that a lot of hpricot code is written in java... alt
I just noticed on string they have a lot of extension methods that I
I just noticed this in some code that's been working for months. Though it
As I hack through our code base I just noticed this function. It converts
I just started using Qt and noticed that in each example code folder there
I just noticed that you can do this in C#: Unit myUnit = 5;
Just noticed this and wanted to mention it. If anyone has seen this issue
I have just noticed that when i call the following code from a console
We have an issue whereby we are using this code below. Its just a

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.