Structured Exceptions (SE) from standard library calls

119 views Asked by At

I've got code that calls ::fgetpos, which results in a kernel exception that can't be caught (I have option /ehs in my VS 2008 project). But I can't help think that standard library routines should never throw these kinds of exceptions.

update: I've tried calling ::fgetpos(0, &foo), which is clearly wrong, and I indeed received a kernel-level exception. I'm baffled. Why would the C++ standard library not perform the most basic of argument checks (check for null-pointer) and raise a std::invalid_argument?

Do any standard library routines perform such basic checks, or do they all happily cause program termination?

1

There are 1 answers

0
GManNickG On

Why would the C++ standard library not perform the most basic of argument checks (check for null-pointer)

Because you can do that yourself if you need the check. The philosophy of C++ is that you don't pay for what you don't need. If I'm a smart programmer and will never pass invalid arguments to the function, why should I have my program's performance potentially suffer with needless checks?

This is why std::vector, for example, provides both operator[] and at(), where the latter performs a bounds-check and the former doesn't. If you need the check, add it.