From 25910a7aa5b344c6c81bd2ddee4b110efb07ec51 Mon Sep 17 00:00:00 2001 From: Lukas Cejka <lukas.ostatek@gmail.com> Date: Sun, 23 Jun 2019 18:17:35 +0200 Subject: [PATCH] Initial commit --- src/TNL/Exceptions/HostBadAlloc.h | 39 +++++++++++++++++++++++++++++++ 1 file changed, 39 insertions(+) create mode 100644 src/TNL/Exceptions/HostBadAlloc.h diff --git a/src/TNL/Exceptions/HostBadAlloc.h b/src/TNL/Exceptions/HostBadAlloc.h new file mode 100644 index 0000000000..2f0abeb05f --- /dev/null +++ b/src/TNL/Exceptions/HostBadAlloc.h @@ -0,0 +1,39 @@ +/*************************************************************************** + HostBadAlloc.h - description + ------------------- + begin : Apr 17, 2019 + copyright : (C) 2017 by Tomas Oberhuber et al. + email : tomas.oberhuber@fjfi.cvut.cz + ***************************************************************************/ + +/* See Copyright Notice in tnl/Copyright */ + +// Implemented by: Lukas Cejka + +#pragma once + +#include <new> + +namespace TNL { +namespace Exceptions { + +struct HostBadAlloc + : public std::bad_alloc +{ + HostBadAlloc() + { + // Assert that there is enough space to store the values. +// TNL_ASSERT( Devices::SystemInfo::getFreeMemory() > Matrices::Matrix::getNumberOfMatrixElements() * sizeof( Matrices::Matrix::RealType ), ); + std::cerr << "terminate called after throwing an instance of 'TNL::Exceptions::HostBadAlloc'\n what(): " << what() << std::endl; + std::exit(1); + } + + const char* what() const throw() + { + return "Failed to allocate memory on the Host device: " + "most likely there is not enough space in the host memory."; + } +}; + +} // namespace Exceptions +} // namespace TNL -- GitLab