64,682
社区成员
发帖
与我相关
我的任务
分享
#include <iostream>
using namespace std;
int main()
{
try
{
string str = "hello";
cout<<str.at(10);
}
catch(...)
{
cout<<"I caught you! ^_^"<<endl;
}
return 0;
}
#include <iostream>
using namespace std;
#include <string.h>
class MyString
{
private:
const char *content;
public:
MyString(const char *s) : content(s)
{
}
char operator[] (int index)
{
if(content == NULL)
throw "Null Point!";
else if(index >= (int)strlen(content))
throw "index out of bound!";
else
return content[index];
}
};
void main(void)
{
MyString s1 = NULL;
try
{
char a = s1[0];
}
catch(const char *info)
{
cout << info << endl;
MyString s2 = "Hello";
try
{
char a = s2[10];
}
catch(const char *info2)
{
cout << info2 << endl;
}
}
}
#include <iostream>
using namespace std;
int main()
{
try
{
cout<<"In try block!"<<endl;
throw 1;
}
catch(...)
{
cout<<"I caught you! ^_^"<<endl;
}
return 0;
}
int main()
{
try
{
cout<<"In try block!"<<endl;
throw 1;
}
catch(...)
{
cout<<"I caught you! ^_^"<<endl;
}
return 0;
}