Click to See Complete Forum and Search --> : Calling all Exceptions Guru's
gingerspen
May 1st, 2003, 01:44 PM
I'm new to exceptions and I find myself struggling a little. Can some tell me why this doesn't work?
FILE* hFile;
try
{
// Assume hFile has not been initialised on purpose to generate exception
//This should raised an exception and jump to the catch block.
fputs("123", hFile);
......
}
catch( ... )
{
Do_something();
}
As I understand it, catch( ...) should catch all exceptions but in this case it doesn't. Can anyone help?
Spencer
Paul McKenzie
May 1st, 2003, 02:14 PM
Originally posted by gingerspen
I'm new to exceptions and I find myself struggling a little. Can some tell me why this doesn't work?
The 'C' FILE* streams do not throw exceptions. Unless the underlying fputs() code does a divide by 0, an illegal kernel memory access, or something else that would trigger a system crash, an exception will never be thrown.
Regards,
Paul McKenzie
Andreas Masur
May 1st, 2003, 02:36 PM
In addition to Paul's answer...the exception mechanism was introduced with C++ therefore it will not work with ANSI C standard functions...
gingerspen
May 2nd, 2003, 12:33 AM
Originally posted by Paul McKenzie
The 'C' FILE* streams do not throw exceptions. Unless the underlying fputs() code does a divide by 0, an illegal kernel memory access, or something else that would trigger a system crash, an exception will never be thrown.
Regards,
Paul McKenzie
Paul, thank you very much for your help.
Spencer
gingerspen
May 2nd, 2003, 12:33 AM
Originally posted by Andreas Masur
In addition to Paul's answer...the exception mechanism was introduced with C++ therefore it will not work with ANSI C standard functions...
Andreas, thank you very much for your help.
Spencer
Gabriel Fleseriu
May 2nd, 2003, 01:19 AM
As a side comment: C++ exceptions are synchronous. There is a second kind of exceptions, structured exceptions (SE), that are asynchronous (and are not part of the C++ standard). An access violation is a SE. Now, Microsoft claims that a C++ catch(...) handler (note the ellipsis) will also catch SEs (VC 6.0). However I saw at least one example where this wasn't true.
codeguru.com
Copyright Internet.com Inc., All Rights Reserved.