diff options
-rw-r--r-- | includes/Exceptions.h | 27 |
1 files changed, 27 insertions, 0 deletions
diff --git a/includes/Exceptions.h b/includes/Exceptions.h index e17e468..0563090 100644 --- a/includes/Exceptions.h +++ b/includes/Exceptions.h @@ -21,6 +21,33 @@ class GeneralException { char * m_msg; }; +static inline void * malloc(size_t size) throw (GeneralException) { + void * r = ::malloc(size); + + if (!r && size) + throw GeneralException("Failed to allocate memory."); + + return r; +} + +static inline void * calloc(size_t count, size_t size) throw (GeneralException) { + void * r = ::calloc(count, size); + + if (!r && ((count * size) != 0)) + throw GeneralException("Failed to allocate memory."); + + return r; +} + +static inline void * realloc(void * previous, size_t size) throw (GeneralException) { + void * r = ::realloc(previous, size); + + if (!r && size) + throw GeneralException("Failed to allocate memory."); + + return r; +} + static inline void AssertHelper(const String & msg) throw(GeneralException) { throw GeneralException(msg); } class ClassName { |