forked from ziobron/memory_management
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathexample3.cpp
More file actions
40 lines (36 loc) · 674 Bytes
/
example3.cpp
File metadata and controls
40 lines (36 loc) · 674 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
34
35
36
37
38
39
#include <iostream>
#include <stdexcept>
using namespace std;
class Resource
{
public:
void use(const char* N)
{
cout << "Using resource. Passed " << *N << endl;
if (*N == 'd')
{
throw logic_error("Passed d. d is prohibited.");
}
};
};
int main(int argc, char* argv[])
{
if(argc != 2)
{
cerr << "You need to pass 1 argument" << endl;
exit(-1);
}
const char* N = argv[1];
Resource* rsc = nullptr;
try
{
rsc = new Resource();
rsc->use(N);
delete rsc;
}
catch (logic_error & e)
{
cout << e.what() << endl;
}
return 0;
}