It seems when we include <iostream>
header, <exception>
and <stdexcept>
headers are included automatically.
Question is why the reference sites like cppreference and cplusplus.com include <exception>
while explaining exception handling?
Is it necessary to include <exception>
or <stdexcept>
?
You should always follow documentation. When documentation says that in order to use ceratain construct you need to include certain header, the header must be included. Otherwise, tomorrow iostream
will stop including the header, and your program will fail to compile or worse - will behave unexpectedly.
You should always include what you use. The C++ standard doesn't state that any particular header has to include another, they are free to do so for convenience. But note that just because that happens to be the case for one compiler, it may not be the case on another (e.g. Visual Studio vs gcc)
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With