-
Notifications
You must be signed in to change notification settings - Fork 0
/
error.h
57 lines (47 loc) · 1.32 KB
/
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
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
/*
* File: error.h
* -------------
* This file defines the <code>ErrorException</code> class and the
* <code>error</code> function.
*/
#ifndef _error_h
#define _error_h
#include <string>
#include <exception>
/*
* Class: ErrorException
* ---------------------
* This exception is thrown by calls to the <code>error</code>
* function, which makes it possible for clients to respond to error
* conditions. Typical code for catching errors looks like this:
*
*<pre>
* try {
* . . . code in which an error might occur . . .
* } catch (ErrorException & ex) {
* . . . code to handle the error condition . . .
* }
*</pre>
*
* If an <code>ErrorException</code> is thrown at any point in the
* range of the <code>try</code> (including in functions called from
* that code), control will jump immediately to the error handler.
*/
class ErrorException : public std::exception {
public:
ErrorException(std::string msg);
virtual ~ErrorException() throw ();
virtual std::string getMessage();
virtual const char *what() const throw ();
private:
std::string msg;
};
/*
* Function: error
* Usage: error(msg);
* ------------------
* Signals an error condition in a program by throwing an
* <code>ErrorException</code> with the specified message.
*/
void error(std::string str);
#endif