2019-05-19から1日間の記事一覧

例外でエラーを知らせる / 例外の型ごとにcatchブロックを設ける

#include <iostream> #include <string> using namespace std; int main(){ for (int i = 0; i < 5; i++) { try { switch(i) { case 0 : throw i ; break; // int型の例外を投げる。 case 1 : throw string("1.0000"); break; // string型の例外を投げる。 case 2 : throw 2.1 </string></iostream>…

例外でエラーを知らせる / 型の異なる複数の例外を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;</string></iostream>…