It is not specified if call to ostream operator<< can fail or throw any exception and I have never encounter this.
- Is there a case where ostream operator<< could fail ?
- If no, why standard does not put noexcept specifier to these overloads ?
- Is the following overload valid ? good practice ? commonly used ?
- Same question for istream operator>> ?
struct MyClass {
int data;
// I/O operators with noexcept specifier
friend std::istream& operator>>(std::istream &in, MyClass &obj) noexcept;
friend std::ostream& operator<<(std::ostream &out, const MyClass &obj) noexcept;
};