-
Notifications
You must be signed in to change notification settings - Fork 0
debug.h ~ debug ~ noexcept_on_fail
Baptiste Thémine edited this page Jul 5, 2020
·
5 revisions
std::ios& noexcept_on_fail(std::ios &ios) noexcept;
Disables iostream exceptions.
If manipulation of ios
fails, you will have to check its state.
By default, iostream exceptions are disabled.
-
ios
--> reference to an iostream object.
Returns a reference to ios
passed in argument.
Never throws exception.
In the following example, we check if user correctly inputs a number.
#include <iostream>
#include <JLC/debug.h>
int main(){
std::cin >> debug::noexcept_on_fail;
int num;
std::cout << "number = ";
if(std::cin >> num) std::cout << num << std::endl;
else std::cout << "INPUT ERROR" << std::endl;
}
>./test.exe
number = 42
42
>./test.exe
number = test
INPUT ERROR