これらのクラス群に反映されているエラーモデルの種類
- runtime error 実行時エラー
- logic error 論理エラー
実行時エラーは、プログラムの制御の及ばない事象を起因とする。
論理エラーは、プログラムの内部的論理の誤りに起因する。
以下の様なクラスが定義されている。
- exception
- runtime error
- range_error
- overflow_error
- underflow_error
- logic error
- domain_error
- invalide_argument
- length_error
- out_of_range
explicit T(const string& what_arg){} 指定したメッセージをもつ例外オブジェクトの生成
explicit T(const char* what_arg){} C++11 指定したメッセージをもつ例外オブジェクトの生成
virtual const char* what() const noexcept; メッセージの取得
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// | |
// stdexcept.cpp | |
// CplusplusPractice | |
// | |
// Created by masai on 2015/05/25. | |
// Copyright (c) 2015年 masai. All rights reserved. | |
// | |
#include <iostream> | |
#include <stdexcept> | |
using namespace std; | |
class processing{ | |
public: | |
void function(){ | |
throw std::logic_error("an logic error."); | |
} | |
}; | |
int main(int argc, char* argv[]){ | |
processing p; | |
try{ | |
p.function(); | |
}catch(const std::logic_error& e){ | |
cout << e.what() <<endl; | |
} | |
} |
0 件のコメント:
コメントを投稿