12/9 c++ question: is this supposed to trigger a catch? Or do I
have to explicitly throw an exception for there to be something
to be catch'ed? My own testing shows that it doesn't throw
any exception on its own, not sure if I'm doing something wrong.
try {
....
char*c = new char[1000000000];
strcpy(c,"blahblahblah.....");
...
}
catch (...)
{
cout << "Out of memory or null ptr exception?" << endl;
}
\_ g++-compiled programs will automatically throw an exception;
VC6, no.
\_ VC6 was released before the C++ standard was ratified. In the
standard, when new fails, it throws an exception.
\_ Ah, I'm using Watcom C, which probably isn't up-to-date on the
recent standard changes. Thanks! -op
\_ Uh, the standard was ratified in 1998 IIRC. Not exactly
recent. However, many compilers allow 'nothrow' by default
for backwards compatibility.
\_ By compiler standards 1998 is probably still "the future".
\_ Actually, are there ANY C++ compilers that are
fully compliant with the standard? I remember
there weren't when I checked a year ago.
\_ You were wrong then. Comeau C++ has been compliant
for at least a year (using the EDG frontend). MS C++
7.1 (.Net 2003) is very compliant, missing only
export and exception specs. |