CPP
cpp
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
/*
Two questions:
1.
Why this code results in core dump? I know issue is due to obj3 as it results into division by 0
But isn't it handled due to try catch block?
2.If problem 1 is solved,how to ensure that obj3 is not valid object? In short, I would like
to restrict other function call on this object and mark that object as invalid.
*/
#include <iostream>
using namespace std;
class clsTest
{
public:
clsTest(string name, int id) : m_strName(name){
try
{
m_intGroupId = (id + 1) / (id - 5);
}
catch (...)
{
}
}
Enter to Rename, Shift+Enter to Preview
OUTPUT
Run