This shows you the differences between two versions of the page.
| Both sides previous revision Previous revision Next revision | Previous revision | ||
|
programming:cpp:exception [2022/05/05 07:30] odagawa |
programming:cpp:exception [2022/05/05 11:09] (current) odagawa |
||
|---|---|---|---|
| Line 1: | Line 1: | ||
| =====例外処理===== | =====例外処理===== | ||
| + | |||
| + | try-catch 文を用いることでプログラムのどこでエラーが起こっているかをスムーズに把握することができる.\\ | ||
| + | '' | ||
| + | 例外クラスは '' | ||
| STL で用意されている例外クラスは以下の通り | STL で用意されている例外クラスは以下の通り | ||
| Line 14: | Line 18: | ||
| int main (int argc, char *argv[]) { | int main (int argc, char *argv[]) { | ||
| - | try { | + | |
| - | if (/ | + | |
| throw std:: | throw std:: | ||
| - | } catch ( std:: | + | |
| - | std::cerr << error << std::endl; | + | std::cerr << error.what() << std:: |
| + | std:: | ||
| + | } catch ( const std:: | ||
| + | std::cerr << error.what() | ||
| std:: | std:: | ||
| - | } | + | |
| - | std:: | + | |
| } | } | ||
| </ | </ | ||