2 Copyright (c) 2000, 2012, Oracle and/or its affiliates. All rights reserved.
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.
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.
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,
20 /* mySTL memory implements exception, runtime_error
24 #ifndef mySTL_STDEXCEPT_HPP
25 #define mySTL_STDEXCEPT_HPP
28 #include <string.h> // strncpy
29 #include <stdlib.h> // size_t
38 virtual ~exception() {} // to shut up compiler warnings
40 virtual const char* what() const { return ""; }
42 // for compiler generated call, never used
43 static void operator delete(void*) { }
45 // don't allow dynamic creation of exceptions
46 static void* operator new(size_t);
50 class named_exception
: public exception
{
52 enum { NAME_SIZE
= 80 };
54 explicit named_exception(const char* str
)
56 strncpy(name_
, str
, NAME_SIZE
);
57 name_
[NAME_SIZE
- 1] = 0;
60 virtual const char* what() const { return name_
; }
62 char name_
[NAME_SIZE
];
66 class runtime_error
: public named_exception
{
68 explicit runtime_error(const char* str
) : named_exception(str
) {}
76 #endif // mySTL_STDEXCEPT_HPP