User Tools

Site Tools


programming:cpp:exception

This is an old revision of the document!


例外処理

STL で用意されている例外クラスは以下の通り

関数説明
std::logic_error 論理エラー
std::runtime_error 実行時エラー
std::bad_alloc メモリ確保時エラー
std::bad_cast 型のキャストエラー
std::out_of_range 添字範囲外
std::invalid_argument 引数無効
int main (int argc, char *argv[]) {
 
try {
 
if (/*例外条件*/)
    throw std::runtime_error("Runtime error : " << "内容");
 
} catch ( std::runtime_error &error ) {
    std::cerr << error << std::endl;
    std::exit(1);
}
 
std::exit(0);
 
}
programming/cpp/exception.1651735801.txt.gz · Last modified: 2022/05/05 07:30 by odagawa