-
Notifications
You must be signed in to change notification settings - Fork 0
/
baseException.cpp
68 lines (58 loc) · 2.44 KB
/
baseException.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
66
67
68
/* This file is part of NFLdecisionTree. It creates decision trees to classify
situations within NFL football games, and displays the plays historically
called in those situations given a set of opponents.
Copyright (C) 2013 Ezra Erb
This program is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License version 3 as published
by the Free Software Foundation.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program. If not, see <http://www.gnu.org/licenses/>.
I'd appreciate a note if you find this program useful or make
updates. Please contact me through LinkedIn (my profile also has
a link to the code depository)
*/
#include<cstring>
#include<cstdio>
#include"baseException.h"
using std::exception;
BaseException::BaseException(const char* file, int line, const char* message) throw()
{
// Copy the file name into the error message
_message[0] = '[';
strncpy(_message + 1, file, 99);
unsigned short length = strlen(_message); // Returns position of NUL at end of string
if (length < MessageSize) {
/* Convert the line number to a string and copy. To avoid a memory allocation,
use C style conversion on the stack and copy */
char temp[15];
sprintf(temp, " %d] ", line);
// NOTE: Nasty C style pointer arithmetic to get the copy to start at the right place
strncpy(_message + length, temp, MessageSize - length);
length = strlen(_message);
}
/* More important to get the message than the location, so if not enough
room, take the message */
if ((length + strlen(message)) >= MessageSize)
strncpy(_message, message, MessageSize);
else
strncpy(_message + length, message, MessageSize - length);
}
// Destructor
BaseException::~BaseException() throw()
{
// All on stack, so nothing to do!
}
// Assignment and copy, required by class exception
BaseException& BaseException::operator=(const BaseException& other) throw()
{
strncpy(_message, other._message, MessageSize);
return *this;
}
BaseException::BaseException(const BaseException& other) throw()
{
*this=other;
}