1、
std:
1 #include2 #include // for cerr 3 //#include // 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 try13 {14 char chD = s1.at(300);15 }16 catch(...)17 {18 printf("err\n");19 }20 21 printf("\n");22 try23 {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 try33 {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