gdcmException.h
Go to the documentation of this file.
/*=========================================================================
Program: GDCM (Grassroots DICOM). A DICOM library
Copyright (c) 2006-2011 Mathieu Malaterre
All rights reserved.
See Copyright.txt or http://gdcm.sourceforge.net/Copyright.html for details.
This software is distributed WITHOUT ANY WARRANTY; without even
the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR
PURPOSE. See the above copyright notice for more information.
=========================================================================*/
#ifndef GDCMEXCEPTION_H
#define GDCMEXCEPTION_H
#include <cassert>
#include <cstdlib> // NULL
#include <exception>
#include <sstream> // ostringstream
#include <stdexcept> // logic_error
#include <string>
// Disable clang warning "dynamic exception specifications are deprecated".
// We need to be C++03 and C++11 compatible, and if we remove the 'throw()'
// specifier we'll get an error in C++03 by not matching the superclass.
#if defined(__clang__) && defined(__has_warning)
# if __has_warning("-Wdeprecated")
# pragma clang diagnostic push
# pragma clang diagnostic ignored "-Wdeprecated"
# endif
#endif
namespace gdcm
{
class Exception : public std::exception
{
typedef std::logic_error StringHolder;
static StringHolder CreateWhat(const char* const desc,
const char* const file,
const unsigned int lineNumber,
const char* const func)
{
assert(desc != nullptr);
assert(file != nullptr);
assert(func != nullptr);
std::ostringstream oswhat;
oswhat << file << ":" << lineNumber << " (" << func << "):\n";
oswhat << desc;
return StringHolder( oswhat.str() );
}
public:
explicit Exception(const char *desc = "None",
const char *file = __FILE__,
unsigned int lineNumber = __LINE__,
// FIXME: __PRETTY_FUNCTION__ is the non-mangled version for __GNUC__ compiler
const char *func = "" /*__FUNCTION__*/)
:
What( CreateWhat(desc, file, lineNumber, func) ),
Description(desc)
{
}
~Exception() throw() override {}
const char* what() const throw() override
{
return What.what();
}
const char * GetDescription() const { return Description.what(); }
private:
StringHolder What;
StringHolder Description;
};
} // end namespace gdcm
// Undo warning suppression.
#if defined(__clang__) && defined(__has_warning)
# if __has_warning("-Wdeprecated")
# pragma clang diagnostic pop
# endif
#endif
#endif
gdcm::Exception::~Exception
~Exception() override
Definition gdcmException.h:83
gdcm::Exception::GetDescription
const char * GetDescription() const
Return the Description.
Definition gdcmException.h:92
gdcm::Exception::Exception
Exception(const char *desc="None", const char *file=__FILE__, unsigned int lineNumber=__LINE__, const char *func="")
Definition gdcmException.h:72
gdcm::Exception::what
const char * what() const override
what implementation
Definition gdcmException.h:86
gdcm
Definition gdcmASN1.h:21