views:

330

answers:

5

Is it good to define a new macro that craters my need of showing failed assertion to user and with just enough information for developers to debug the issue.

Message for user, what the user should do with this message at last information for the developer

#define ASSERT(f) \
    do \
    { \
    if (!(f) && AfxAssertFailedLine(THIS_FILE, __LINE__)) \
     AfxDebugBreak(); \
    } while (0) \

sample message fn that we use,

MessageBox(_T("Error in finding file."),_T("TITLE"),MB_ICONERROR);
+3  A: 

There's a couple things I would consider from the end-user's standpoint.

  • Who is the target audience? If your grandmother is using this program, would these assertion messageboxes accomplish anything beyond frustrating her?
  • How frequently would these assertions fail? One assertion during a week of normal usage would certainly justify keeping it in the program, but several an hour would just irritate the user. The middle ground is obviously very difficult to gauge.
  • Have you considered putting in an "Enable Assertions" preference into the program? That way, if there are some more technical-minded (and helpful) users, they can explicitly enable the assertions and inform you when things go wrong; and if some users have no idea what an assertion is or why they are getting popups in your program, they can just disable the assertions and continue to happily use your program. Hopefully, you can put a "Do not show me assertion failure messages anymore" checkbox on the popup.

I'd say that forcing the assertion popups on users would be a plain bad idea, but allowing them to enable or disable the warnings would be a good approach.

Mark Rushakoff
+3  A: 

Message Box MUST NOT show any information for developers. information for developers must be saved in some log-file and user asked for transmit file to developer.

PS: You question is extremely short.

vitaly.v.ch
A: 

Never expose any internals to users unless they are all programmers instead use log-files and pop-up with proposition of sending(automatically) those logs to devs.

przemo_li
+1  A: 

Just after asking this question I read about SMART_ASSERT mentioned by Andrei Alexandrescu and John Torjo in Enhancing Assertions.This looks like that is right candidate for me, but the link to the source in that article is broken, can someone give me the source code for SMART_ASSERT?

yesraaj
SMART_ASSERT is indeed extremely useful. It not only shows the file and line of assert failure, but displays the contents of the variables involved, and offers you the ability to ignore an assert until the end of the session.The source is available here: http://torjo.com/code/smart_assert.zip
Thomas
Thanks..for(;;)
yesraaj
A: 

I would not let users see any real debug info, as it will only make your application look amature.

Secondly, why are you using a do-while loop instead of a regular {} scope ?

rmn
yes it is needed, because it makes developer to add a semicolon after the ASSERT statement.
yesraaj