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

  • Home
  • SEARCH
  • 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 91839
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 10, 20262026-05-10T23:05:34+00:00 2026-05-10T23:05:34+00:00

After reading some threads on misuses of exceptions (basically saying you don’t want to

  • 0

After reading some threads on misuses of exceptions (basically saying you don’t want to unwind the stack if a functions preconditions are incorrect – possibly signalling that all your memory is corrupt or something equally dangerous) I’m thinking about using assert() more often. Previously I have only used assert() as a debug tool and I think this is how a lot of C++ programmers use it. I’m concerned about part of my error handling being turned off by a NDEBUG #define introduced to the runtime builds at some point in the future. Is there a way round this and have others had a problem with this (i.e. should I be worrying about it)?

Thanks, Pat

Edit: The point of the threads I was reading was that if your application is truely buggered then unwinding stack could damage the system, for instance if a destructor wrote something to a file and the file handle was corrupted. I’m not suggesting using assert for normal error handling. The current use case I have is pretty weak but see what you think:

    //check later code won't crash the system   if( buf.length() % 2 )     return false;   // do other stuff that shouldn't affect bufs length   //copy 2 bytes into buf at a time, if length is odd then don't know    //what will happen so use assert to make sure it can't damage anything   assert( !(buf.length() % 2) );   for( i = 0; i != buf.length(); i += 2 )     memcpy( buf + i, data, 2 );   

edit2: the discussion is here: http://groups.google.com/group/comp.lang.c++.moderated/browse_frm/thread/80083ac31a1188da

  • 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. 2026-05-10T23:05:34+00:00Added an answer on May 10, 2026 at 11:05 pm

    You could build your own assert instead of using the stock C assert.h. Your assert won’t be disabled.

    Look at how assert() is implemented in /usr/include/assert.h (or wherever). It’s simply some preprocessor magic eventually calling an ‘assert fail’ function.

    In our embedded environments, we replace assert() all the time.

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

Sidebar

Related Questions

I am new to JPA & Hibernate. After reading some online materials I now
after reading a few articles, I am still not sure I understand Multi-threading to
I have a simple bean @Entity Message.java that has some normal properties. The life-cycle
I'm using sessions in Django to store login user information as well as some
I am having a super hard time compiling and using TagLib 1.6.3 in my
I've learned that you should usually stick with either forking or threading to avoid
Today I was doing the thread ring exercise from the Programming Erlang book and
I'm currently working on solving a bug with a site I've been working on
I have a C# code which communicates with three different COM ports. The COM
I am looking to write a contact synchronisation application for windows mobile and google

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.