Re: Try-catch works with structured exception
On Jan 22, 7:55 pm, "Bo Persson" <b...@gmb.dk> wrote:
George2 wrote:
I have tested try-catch works with structured exception, to my
surprise. Previously I think we have to use __try and __except.
Any comments? Here is my test code and I am using Visual Studio
2008.
[Code]
#include <iostream>
using namespace std;
int main()
{
int* address = NULL;
try{
(*address) = 1024;
} catch (...)
{
cout << "access violation caught" << endl;
}
return 0;
}
[/Code]
That's a known bug in MS' exception handling.
I don't see how it can be considered a bug. I'm pretty sure
they do it intentionally. And of course, it's perfectly
standard conformant.
A catch(...) statement
should only pick up things that are thrown.
In a program which doesn't contain undefined behavior. Once you
encounter undefined behavior, the standard doesn't say what may
happen.
Whether the VC++ behavior is really desirable is another
question---I can't think of any case where a core dump wouldn't
be preferable. But it's certainly better than just stumbling on
randomly. Or locking up the hardware, which is what would
happen on one machine I worked on, many, many years ago.
--
James Kanze (GABI Software) email:james.kanze@gmail.com
Conseils en informatique orient=E9e objet/
Beratung in objektorientierter Datenverarbeitung
9 place S=E9mard, 78210 St.-Cyr-l'=C9cole, France, +33 (0)1 30 23 00 34