-
Notifications
You must be signed in to change notification settings - Fork 0
/
cmpt_error.h
30 lines (24 loc) · 844 Bytes
/
cmpt_error.h
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
WeChat: cstutorcs
QQ: 749389476
Email: tutorcs@163.com
// cmpt_error.h
// By defining CMPT_ERROR_H, we avoid problems caused by including this file
// more than once: if CMPT_ERROR_H is already defined, then the code is *not*
// included.
#ifndef CMPT_ERROR_H
#define CMPT_ERROR_H
#include <string>
#include <stdexcept>
// C++ already has function called error, and so we put our error function
// inside a namespace called cmpt. Thus, to use this error function, we will
// write its full name, cmpt::error.
namespace cmpt {
// runtime_error is a pre-defined C++ object meant to be "thrown" when an
// error occurs while a program is running. When it is thrown, the program
// will end and print the given error message.
inline void error(const std::string& message)
{
throw std::runtime_error(message);
}
} // namespace cmpt
#endif