// invalid_argument

#include <bitset>

#include <iostream>

using namespace std;

 

int main(void)

{

try

{

// binary wrongly represented by char X

// template based

bitset<32> bitset(string("0101001X01010110000"));

}

catch (exception &err)

{

cerr<<"Caught "<<err.what()<<endl;

cerr<<"Type "<<typeid(err).name()<<endl;

};

}

 

Output example:

 

Caught invalid bitset<N> char

Type class std::invalid_argument

Press any key to continue . . .

 

 

C and C++ Programming Resources | C & C++ Code Example Index