-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathexceptionType.cpp
More file actions
33 lines (30 loc) · 970 Bytes
/
exceptionType.cpp
File metadata and controls
33 lines (30 loc) · 970 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
#include <stdexcept> //preprocessor directive for specific type of exception
#include <fstream> //preprocessor directive for file manipulation
#include <typeinfo> //preprocessor directive for type identification and information
#include <string>
#include <iostream>
using namespace std;
int main() {
string lang = "C++";
int num = 1000000000;
try {
// lang.replace(100,1,"C");
// lang.resize(3*num);
ifstream inFile("noFile.txt");
if (!inFile) {
throw logic_error("File not found");
}
}
catch (out_of_range & e) {
cerr << "Range exception: " << e.what() << endl;
cerr << "Type: " << typeid(e).name() << endl;
cerr << "Program terminated." << endl;
return -1;
}
catch (exception & e) {
cerr << "Exception: " << e.what() << endl;
cerr << "Type: " << typeid(e).name() << endl;
}
cout << "Program continues..." << endl;
return 0;
}