例外でエラーを知らせる / 型の異なる複数の例外をcatch(...)で捕まえる
#include <iostream> #include <string> using namespace std; int main(){ for (int i = 0; i < 3; i++) { try { switch(i) { case 0 : throw i ; break; // int型の例外を投げる。 case 1 : throw "1.0000"; break; // string型の例外を投げる。 case 2 : throw 3.0 ; break; // double型の例外を投げる。 default: break; } } catch(...){ cout << to_string(i) + " 例外発生" << endl; } } return 0; }