std::basic_ios::exceptions(3)
π std::basic_ios::exceptions π
okay bestie, welcome to the std::basic_ios::exceptions(3) page from the C++ Standard Libary β¨ β yes, that's the manual name, and we're keeping it cute and exact. This whole page is about std::basic_ios::exceptions, and it's lowkey iconic how much one little exception mask can do. π
β¨ NAME β¨
std::basic_ios::exceptions β yup, the name is literally std::basic_ios::exceptions, and the original NAME line repeats it too: std::basic_ios::exceptions - std::basic_ios::exceptions. No plot twist, just main-character repetition. π«Ά
πΈ Synopsis πΈ
std::ios_base::iostate exceptions() const; (1)
void exceptions( std::ios_base::iostate except ); (2)
Okay so this is the dynamic duo: it gets and sets the exception mask of the stream. The exception mask is the thing that determines which error states trigger exceptions of type failure. Not me explaining stream lore like it's gossip, but here we are. π
- Returns the exception mask. That's the current one, no cap.
- Sets the exception mask to
except. And bestie, listen: if the stream has an error state covered by the exception mask when called, an exception is immediately triggered. Like, instantly. π¨
π Parameters π
exceptβ exception mask. That's the whole parameter, bestie. Slay. π
π Return value π
- The current exception mask. That's what overload
(1)hands back. β¨ (none)β overload(2)returns nothing, literally no return value. π«Ά
π¦ Notes π¦
π§ This section is incomplete.
Reason: discuss LWG2349 and link from ios_base::clear, and from (un)formatted(i/o)utputfunction requirement pages (or perhaps the behavior should be fully elaborated on the requirement pages and linked from here). That's the note, and we're keeping all the exact bits because we do not erase the lore. π
π See also π
stackoverflow.com/a/35089910β the linked Stack Overflow answer. Go click, bestie. π¦
π Example π
// Run this code
#include <fstream>
#include <iostream>
int main()
{
int ivalue;
try
{
std::ifstream in("in.txt");
in.exceptions(std::ifstream::failbit); // may throw
in >> ivalue; // may throw
}
catch (const std::ios_base::failure& fail)
{
// handle exception here
std::cout << fail.what() << '\n';
}
}
π Possible output π
Possible output:
basic_ios::clear: iostream error
π Category π
Todo with reason
signed, sealed, and served by http://cppreference.com on 2024.06.10 π β this was std::basic_ios::exceptions(3), source and version/date stamp included, and she ate. πβ¨
π¦ where this page comes from
- nixpkgs unstable: stdman 2024.07.05
- opensuse-leap 16.0: stdman 2024.07.05-bp160.1.9 Β· MIT
- π girlified by deepseek-ai/DeepSeek-V4.1-Flash-1017 on : a language model's rewrite of the original, under its terms