CookMem 1.4.0
A C++ memory context / allocator
Loading...
Searching...
No Matches
exception.h
1/*
2 * Copyright (c) 2021-2026 Heng Yuan
3 *
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
7 *
8 * http://www.apache.org/licenses/LICENSE-2.0
9 *
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
15 */
16#ifndef COOK_EXCEPTION_H
17#define COOK_EXCEPTION_H
18
19#include "config.h"
20
21namespace cookmem
22{
23
34
39{
40public:
53 Exception (MemError_et error, const char* msg, const char* file = nullptr, int line = 0)
54 : m_error (error),
55 m_msg (msg),
56 m_file (file),
57 m_line (line)
58 {
59 }
60
66 MemError_et getError () const { return m_error; }
67
73 const char* getMessage () const { return m_msg; }
74
80 const char* getFile () const { return m_file; }
81
87 int getLine () const { return m_line; }
88private:
89 const MemError_et m_error;
90 const char* m_msg;
91 const char* m_file;
92 int m_line;
93};
94
95} // namespace cookmem
96
97#if COOKMEM_DEBUG > 0
98#define COOKMEM_ASSERT(b) do { if (!(b)) throw cookmem::Exception (cookmem::MEM_ERROR_ASSERT, "assertion failure.", __FILE__, __LINE__); } while (0)
99#else // COOKMEM_DEBUG
100#define COOKMEM_ASSERT(b)
101#endif // COOKMEM_DEBUG
102
103#endif // COOK_EXCEPTION_H
Definition exception.h:39
MemError_et getError() const
Definition exception.h:66
const char * getMessage() const
Definition exception.h:73
const char * getFile() const
Definition exception.h:80
int getLine() const
Definition exception.h:87
Exception(MemError_et error, const char *msg, const char *file=nullptr, int line=0)
Definition exception.h:53
Definition allocator.h:39
Definition allocator.h:29
MemError_et
Definition exception.h:28
@ MEM_ERROR_PADDING
padding bytes after an allocation were overwritten
Definition exception.h:32
@ MEM_ERROR_GENERAL
general error
Definition exception.h:29
@ MEM_ERROR_DOUBLE_FREE
freeing an already free pointer
Definition exception.h:31
@ MEM_ERROR_ASSERT
assertion failure (COOKMEM_DEBUG builds only)
Definition exception.h:30