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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 25, 20262026-05-25T15:42:45+00:00 2026-05-25T15:42:45+00:00

I read about concern that the overly use of noexcept may hinder a testable

  • 0

I read about concern that the overly use of noexcept may hinder a testable library.

Consider:

T& vector::front() noexcept {
    assert(!empty());         // <- this may throw in some test-frameworks
    return data[0];
}

With the annotation with noexcept the compiler may optimize exception-code out, which would/could prevent proper handling of assert() (or whichever function the author wants to use here for his tests).

Therefore, I wonder, if it is feasible in a library to never use an unconditional noexcept but to always “link” it with a am-I-in-a-test-condition. Like this:

#ifdef NDEBUG    // asserts disabled
static constexpr bool ndebug = true;
#else            // asserts enabled
static constexpr bool ndebug = false;
#end

T& vector::front() noexcept(ndebug) {
    assert(!empty());
    return data[0];
}

and then maybe add it as a macro (although, I hate that):

#define NOEXCEPT noexcept(ndebug)

T& vector::front() NOEXCEPT {
    assert(!empty());
    return data[0];
}

What do you think? Does this make any sense at all? Or is it not feasible? Or does it not solve the problem? Or is there no problem at all? 🙂

  • 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-25T15:42:46+00:00Added an answer on May 25, 2026 at 3:42 pm

    If you cannot prove that a function will not emit an exception then you should not tag it with noexcept. It’s that simple.

    That said, noexcept(ndebug) seems reasonable to me. I see no reason to hide it behind a macro. Template functions often have verbose noexcept conditions.

    If the function within the asset can throw during test modes then your program can spontaneously std::terminate during test mode. (It’s a lot like an implicit assert actually.)

    The only downside I can see is that if this happens you won’t get a line number and hint message. That, and the compiler ought to warn you if you call a noexcept(false) function from a noexcept(true) one, so you might get some noise.

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

Sidebar

Related Questions

I read about an inheritance feature in PostgreSQL that seemed pretty neat. Unfortunately I
I read about ContactsContract.CommonDataKinds.GroupMembership , but I can't figure out what URI use to
The most common theme I read about why to use node.js is for high
I've just read about MVC3's new CompareAttribute that you can apply to a model's
Read about Server push here . I want to push data to client from
I read about the Conditional attribute today. According to MSDN: Applying ConditionalAttribute to a
I read about using the CASE expression inside the WHERE clause here: http://scottelkin.com/sql/using-a-case-statement-in-a-sql-where-clause/ I'm
Ive read about it and to be honest it all seems like a bunch
I read about small talk being completely object oriented.. is C++ also completely object
I read about using <context:component-scan base-package=tld.mydomain.business> <context:include-filter type=annotation expression=org.springframework.stereotype.Service/> </context:component-scan> and annotate my service

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.