VC++异常捕获??

1、

std:

 1 #include <string>
 2 #include<iostream> // for cerr
 3 //#include <stdexcept> // for what ?
 4 using namespace std;
 5 
 6 
 7 int _tmain(int argc, _TCHAR* argv[])
 8 {
 9     string s1("UIPower");
10     char chA = s1[2];
11 
12     try
13     {
14         char chD = s1.at(300);
15     }
16     catch(...)
17     {
18         printf("err\n");
19     }
20 
21     printf("\n");
22     try
23     {
24         char chD = s1.at(300);
25     }
26     catch(std::out_of_range &ex)
27     {
28         std::cerr << ex.what() << " Line:" << __LINE__ << " File:" << __FILE__ << endl;
29     }
30 
31     printf("\n");
32     try
33     {
34         char chD = s1.at(300);
35     }
36     catch(std::exception &ex)
37     {
38         std::cerr << ex.what() << " Line:" << __LINE__ << " File:" << __FILE__ << endl;
39     }
40 
41     system("pause");
42     return 0;
43 }

 

2、

 

C

 

posted @ 2016-01-27 13:29  CodeSkill  阅读(515)  评论(0编辑  收藏  举报