Handy non-breaking debug macro

Every now and then I end up with some weird debugging thing that’s hard to handle. Usually I just want to know the value of a variable when something condition is not met (a breakpoint or a jassert(condition) will usually suffice, but sometimes it’s not possible to view the debug output without causing further problems - e.g. the act of bringing the app window back causes the problem to get buried or retriggered). Sometimes it can be useful to access values without breaking the program to investigate.

So, a quick neat way to put debug output right there on your app (without adding anything specific for it) is with the following macro:

#ifdef JUCE_DEBUG
#define JALERT(condition,output)	if (!condition) AlertWindow::showMessageBox (AlertWindow::WarningIcon,T("Juce Alert"),output);
#else
#define JALERT(condition,output)
#endif

In a debug build, if the condition is not true, an AlertWindow will pop up displaying the message [which could include variable values or whatever you like]. It’s not useful for every scenario, but can help in quickly identifying issues without causing the program to break for normal debug checking.

1 Like