Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <iostream>
- #include <algorithm>
- #include <fstream>
- #include <math.h>
- #include <vector>
- #include <string>
- #include <sstream>
- #include <map>
- #include <set>
- using namespace std;
- class MyExc {
- private:
- string _msg;
- public:
- MyExc(const string& msg) : _msg(msg) {};
- const string& getMsg() const {
- return _msg;
- }
- };
- void run() {
- int a[100];
- int init_sz = 10;
- for (int i = 0; i < init_sz; ++i) {
- a[i] = i * 29;
- }
- int n;
- cin >> n;
- throw MyExc("Ecx in run");
- try {
- if (n < 0) {
- string s = "Error: n < 0\n";
- throw s;
- }
- if (n >= init_sz) {
- throw "Error: n >= init_sz\n";
- }
- throw 1;
- cout << a[n] << endl;
- }
- catch (const char* e) {
- cerr << "Char* error: " << e << endl;
- }
- catch (const string& e) {
- cout << "String error: " << e << endl;
- }
- cout << "End of run" << endl;
- }
- int main() {
- try {
- run();
- cout << "after run\n";
- }
- catch (const MyExc& a) {
- cerr << "Exc in main " << a.getMsg() << "\n";
- }
- cout << "End\n";
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment