Commit 886407cc authored by thomas.forbriger's avatar thomas.forbriger
Browse files

ticket10: removed files containing duplicate exception class

This is a legacy commit from before 2015-03-01.
It may be incomplete as well as inconsistent.
See COPYING.legacy and README.history for details.
parent d07df5c6
/*! \file error.cc
* \brief exceptions and error handling macros (implementation)
*
* ----------------------------------------------------------------------------
*
* $Id$
* \author Thomas Forbriger
* \date 27/11/2002
*
* exceptions and error handling macros (implementation)
*
* Copyright (c) 2002 by Thomas Forbriger (IMG Frankfurt)
*
* ----
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
* ----
*
* REVISIONS and CHANGES
* - 27/11/2002 V1.0 Thomas Forbriger
* - 25/01/2014 V1.1 copied from libtsxx
*
* ============================================================================
*/
#define TSXX_ERROR_CC_VERSION \
"TSXX_ERROR_CC V1.1"
#define TSXX_ERROR_CC_CVSID \
"$Id$"
#include <iostream>
#include <tsxx/error.h>
using std::cerr;
using std::endl;
namespace ts {
namespace error {
//! initialize and instantiate
bool Exception::Mreport_on_construct=true;
std::stack<bool> Exception::Mprevious_report_state;
//! construct from nothing
Exception::Exception():
Mmessage(NULL), Mfile(NULL), Mline(0), Mcondition(NULL)
{ if (this->report_on_construct_is_true()) { base_report(); } }
//! construct with message
Exception::Exception(const char* message):
Mmessage(message), Mfile(NULL), Mline(0), Mcondition(NULL)
{ if (this->report_on_construct_is_true()) { base_report(); } }
//! construct with message and file info
Exception::Exception(const char* message,
const char* condition):
Mmessage(message), Mfile(NULL), Mline(0), Mcondition(condition)
{ if (this->report_on_construct_is_true()) { base_report(); } }
//! construct with message and file info
Exception::Exception(const char* message,
const char* file,
const int& line):
Mmessage(message), Mfile(file), Mline(line), Mcondition(NULL)
{ if (this->report_on_construct_is_true()) { base_report(); } }
//! construct with message and file info and condition
Exception::Exception(const char* message,
const char* file,
const int& line,
const char* condition):
Mmessage(message), Mfile(file), Mline(line), Mcondition(condition)
{ if (this->report_on_construct_is_true()) { base_report(); } }
//! switch on
void Exception::report_on_construct()
{
Mprevious_report_state.push(Mreport_on_construct);
Mreport_on_construct=true;
}
//! switch off
void Exception::dont_report_on_construct()
{
Mprevious_report_state.push(Mreport_on_construct);
Mreport_on_construct=false;
}
//! restore
void Exception::restore_report_state()
{
if (!Mprevious_report_state.empty())
{
Mreport_on_construct=Mprevious_report_state.top();
Mprevious_report_state.pop();
}
}
//! report
void Exception::report() const
{
base_report();
}
//! report
void Exception::base_report() const
{
std::cout.flush();
cerr << "Exception report:" << endl;
if (Mmessage==NULL)
{
cerr << " No message" << endl;
}
else
{
cerr << " message: " << Mmessage << endl;
}
if (Mfile!=NULL)
{
cerr << " triggered in \"" << Mfile << "\" at line #" << Mline << endl;
}
if (Mcondition!=NULL)
{
cerr << " by test condition:" << endl
<< " \"" << Mcondition << "\"" << endl;
}
cerr.flush();
}
} // namespace error
} // namespace ts
/* ----- END OF error.cc ----- */
/*! \file error.h
* \brief exceptions and error handling macros (prototypes)
*
* \ingroup error_h
* ----------------------------------------------------------------------------
*
* $Id$
* \author Thomas Forbriger
* \date 27/11/2002
*
* exceptions and error handling macros (prototypes)
*
* Copyright (c) 2002 by Thomas Forbriger (IMG Frankfurt)
*
* ----
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
* ----
*
* REVISIONS and CHANGES
* - 27/11/2002 V1.0 Thomas Forbriger
* - 28/04/2006 V1.1 provide explicit virtual destructor
* - 11/0/2007 V1.2 added a few macros
* - 25/01/2014 V1.3 copied from libtsxx
*
* ============================================================================
*/
// include guard
#ifndef TSXX_ERROR_H_VERSION
#define TSXX_ERROR_H_VERSION \
"TSXX_ERROR_H V1.3"
#define TSXX_ERROR_H_CVSID \
"$Id$"
#include<stack>
namespace ts {
/*! \defgroup group_error Error handling module
*/
/*! \brief Interface provided through error.h
* \defgroup error_h Interface provided through error.h
* \ingroup group_error
*/
/*! \brief Error handling
*
* \ingroup group_error, error_h
* You may find the exception base class here.
*/
namespace error {
/*! \brief Base class for exceptions
*
* This is an exception base class. It holds some information about the
* reason for throwing the exception. The information is printed to cerr
* through function report(). This function may be overloaded by a derived
* type. But its functionality is still accessible through base_report().
*
* The standard behaviour is to print ou the message during object
* initialization. If you don't like this, call dont_report_on_construct().
*
* \ingroup group_error, error_h
* \sa TSXX_Xassert
*/
class Exception
{
public:
//! Creates exception with no explaning comments
Exception();
//! Creates an exception with an explanation message
Exception(const char* message);
//! Creates an exception with message and failed assertion
Exception(const char* message,
const char* condition);
//! Create with message, failed assertion, and code position
Exception(const char* message,
const char* file,
const int& line,
const char* condition);
//! Create with message and code position
Exception(const char* message,
const char* file,
const int& line);
//! provide explicit virtual destructor
virtual ~Exception() { }
//! Screen report
virtual void report() const;
//! Issue a screen report on construction of exception
static void report_on_construct();
//! Issue NO screen report on construction of exception
static void dont_report_on_construct();
//! Restore previous report state
static void restore_report_state();
protected:
bool report_on_construct_is_true() const
{ return Mreport_on_construct; }
private:
//! Screen report
void base_report() const;
//! Shall we print to cerr at construction time?
static bool Mreport_on_construct;
//! pointer to message string
const char* Mmessage;
//! pointer to file name string
const char* Mfile;
//! pointer to line number in source file
int Mline;
//! pointer to assertion condition text string
const char* Mcondition;
//! a place to store previous report state
static std::stack<bool> Mprevious_report_state;
}; // class exception
} // namespace error
} // namespace ts
/*======================================================================*/
//
// preprocessor macros
// ===================
/*! \brief Check an assertion and report by throwing an exception
*
* \ingroup group_error, error_h
* \param C assert condition
* \param M message of type char*
* \param E exception class to throw
*/
#define TSXX_Xassert(C,M,E) \
if (!(C)) { throw( E ( M , __FILE__, __LINE__, #C )); }
/*! \brief Check an assertion and report by throwing an exception
*
* \ingroup group_error, error_h
* \param C assert condition
* \param M message of type char*
*/
#define TSXX_assert(C,M) TSXX_Xassert( C , M , ts::error::Exception )
/*! \brief Abort and give a message
*
* \ingroup group_error, error_h
* \param M message of type char*
* \param E exception class to throw
*/
#define TSXX_abort(M) \
throw( ts::error::Exception ( M , __FILE__, __LINE__ ))
#define TSXX_illegal TSXX_abort("illegal call!")
/*! \brief Check an assertion and report only.
*
* \ingroup group_error
* \param C assert condition
* \param M message of type char*
* \param V any values that should be output (comment)
* a sequence of values and output operators
*/
#define TSXX_report_assert(C,M,V) \
if (!(C)) { \
ts::report_violation(M, __FILE__, __LINE__, #C); \
std::cerr << "* comment: " << V << std::endl; \
std::cerr << std::endl; \
std::cerr.flush(); \
}
/*! \brief Macro to distinguish between fatal and non fatal assertions.
*
* \ingroup group_error
* \param F true for non fatal behaviour
* \param C assert condition
* \param M message of type char*
* \param V any values that should be output (comment)
* a sequence of values and output operators
*/
#define TSXX_nonfatal_assert(F,C,M,V) \
if (F) { TSXX_report_assert(C,M,V) } else { TSXX_assert(C,M) }
#endif // TSXX_ERROR_H_VERSION (includeguard)
/* ----- END OF error.h ----- */
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment