MySQL 5.6.14 Source Code Document
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
stdexcept.hpp
1 /*
2  Copyright (c) 2000, 2012, Oracle and/or its affiliates. All rights reserved.
3 
4  This program is free software; you can redistribute it and/or modify
5  it under the terms of the GNU General Public License as published by
6  the Free Software Foundation; version 2 of the License.
7 
8  This program is distributed in the hope that it will be useful,
9  but WITHOUT ANY WARRANTY; without even the implied warranty of
10  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
11  GNU General Public License for more details.
12 
13  You should have received a copy of the GNU General Public License
14  along with this program; see the file COPYING. If not, write to the
15  Free Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston,
16  MA 02110-1301 USA.
17 */
18 
19 
20 /* mySTL memory implements exception, runtime_error
21  *
22  */
23 
24 #ifndef mySTL_STDEXCEPT_HPP
25 #define mySTL_STDEXCEPT_HPP
26 
27 
28 #include <string.h> // strncpy
29 #include <stdlib.h> // size_t
30 
31 
32 namespace mySTL {
33 
34 
35 class exception {
36 public:
37  exception() {}
38  virtual ~exception() {} // to shut up compiler warnings
39 
40  virtual const char* what() const { return ""; }
41 
42  // for compiler generated call, never used
43  static void operator delete(void*) { }
44 private:
45  // don't allow dynamic creation of exceptions
46  static void* operator new(size_t);
47 };
48 
49 
50 class named_exception : public exception {
51 public:
52  enum { NAME_SIZE = 80 };
53 
54  explicit named_exception(const char* str)
55  {
56  strncpy(name_, str, NAME_SIZE);
57  name_[NAME_SIZE - 1] = 0;
58  }
59 
60  virtual const char* what() const { return name_; }
61 private:
62  char name_[NAME_SIZE];
63 };
64 
65 
67 public:
68  explicit runtime_error(const char* str) : named_exception(str) {}
69 };
70 
71 
72 
73 
74 } // namespace mySTL
75 
76 #endif // mySTL_STDEXCEPT_HPP