-
Notifications
You must be signed in to change notification settings - Fork 0
/
exception.cpp
65 lines (51 loc) · 1.06 KB
/
exception.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
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
#include "exception.h"
/**************************************************************
* Author: Keyul Patel
* Date Created: 10/10/15
* Last Modification Date: 10/11/15
* Lab Number: CST 211 Assignment 2
* Filename: exception.cpp
*
*
* Overview: To output messages for exceptions
*
* Input: A string
*
* Output: None
****************************************************************/
Exception::Exception(const char *msg)
{
m_msg = new char[strlen(msg)];
for (unsigned int i = 0; i < strlen(msg); i++)
{
m_msg[i] = msg[i];
}
}
Exception::~Exception()
{
delete []m_msg;
}
char Exception:: getMessage() const
{
return *m_msg;
}
void Exception::setMessage(const char *msg)
{
delete[]m_msg;
m_msg = new char[strlen(msg)];
for (unsigned int i = 0; strlen(msg) < i; i++)
{
m_msg[i] = msg[i];
}
}
Exception &Exception::operator=(const Exception &rhs)
{
delete[] m_msg;
m_msg = new char[strlen(rhs.m_msg)];
setMessage(rhs.m_msg);
return *this;
}
ostream &operator<<(ostream &out, const Exception &thing)
{
return out << thing.getMessage();
}