Skip to content

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;

Description

Disables iostream exceptions. If manipulation of ios fails, you will have to check its state. By default, iostream exceptions are disabled.

Parameters

  • ios --> reference to an iostream object.

Return value

Returns a reference to ios passed in argument.

Exceptions

Never throws exception.

Examples

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

See also

Clone this wiki locally