I created the following code segment which recreates an interesting problem
with C++ exceptions. I am using Visual Studio C++ 6.0 Enterprise Edition.
When the program runs in DEBUG mode the exception is caught in the F2
function handler as I would expect. However when the program runs in
RELEASE mode the exeption is caught in the F1 function handler. The command
that is throwing the exception is the strcspn(). Why does this occur?
//-----------------------------------------------------------------
#include <iostream.h>
#include <string.h>
class EClass
{
public:
void F1(const char* a);
void F2(const char* b);
};
void EClass::F1(const char* a)
{
try
{
F2(a);
}
catch(...)
{
cout << "caught in F1 handler" << endl;
}
}
void EClass::F2(const char* a)
{
int i;
char* b = NULL;
try
{
b = strstr(a, "Test");
i = strcspn(b, "\r\n");
}
catch(...)
{
cout << "caught in F2 handler" << endl;
}
}
int main(int argc, char* argv[])
{
EClass ec;
char a[200];
strcpy(a,"Tes\r\n");
try
{
ec.F1(a);
}
catch(...)
{
cout << "caught in main handler" << endl;
}
return 0;
}
//-----------------------------------------------------------------
Tom
---
Outgoing mail is certified Virus Free.
Checked by AVG anti-virus system (
http://www.grisoft.com).
Version: 6.0.542 / Virus Database: 336 - Release Date: 11/18/2003