assert() is a good way to notify errors but I want to cout an elaborate message.
Of course the following method will work but I needed something better:
if(error){
cout<<"Elaborate message";
assert(0);
}
Good tips anyone?
Printable View
assert() is a good way to notify errors but I want to cout an elaborate message.
Of course the following method will work but I needed something better:
if(error){
cout<<"Elaborate message";
assert(0);
}
Good tips anyone?
Better in what way ?Quote:
Of course the following method will work but I needed something better:
From your description, it's impossible to know what you want.
My apologies.
Here's the actual code:
What you can see in bold are 2 statements. What I wanted was to replace those 2 statements by say:Code:void temp_match_img::makevec(){
if(radpix_set==0) cout<<"The values of the radpix[] array have not yet been calculated!\n";
assert(radpix_set);
int temp;
for(int i=-radius; i<=radius; i++){
for(int j=-radius; j<=radius; j++){
temp=(int)sqrt(float(i*i+j*j));
if(temp<=radius){
rpvec[temp]+=tmimg[i+row][j+col]/radpix[temp];
}
}
}
}
assert_new(radpix_set, "The values of the radpix[] array have not yet been calculated!\n");
Any better method is also appreciated. The problem is that assert prints a lot of stuff that I am not interested in. I can print my own stuff (as can be seen in the code) but the message of assert takes some space. Please let me know if you know a way around.
Regards.
So what you want is an assert window with your own message? Well, you can create such a custom window in your project and display it when you need it instead of assert().
An assert kills the program, so trying to format it well isn't all that useful; the only time you should legitimately encounter it is during debugging, and your debugger will stop at the assertion failure anyway, so you can examine the variables directly.
If you're looking to report a failure on the user's part in a meaningful way, consider using an exception (perhaps throwing a std::runtime_error) instead.
Actually, throwing a std::logic_error is probably more useful than an assert even for debugging, since you can attach a message to it. If it isn't caught, that message gets dumped to the screen.
Perfect!