Commit 15447435 authored by thomas.forbriger's avatar thomas.forbriger Committed by thomas.forbriger
Browse files

startet error module

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.


SVN Path:     http://gpitrsvn.gpi.uni-karlsruhe.de/repos/TFSoftware/trunk
SVN Revision: 1103
SVN UUID:     67feda4a-a26e-11df-9d6e-31afc202ad0c
parent a2917a59
# this is <Makefile>
# ----------------------------------------------------------------------------
# $Id: Makefile,v 1.8 2002-11-20 14:57:37 forbrig Exp $
# $Id: Makefile,v 1.9 2002-11-27 13:05:40 forbrig Exp $
#
# Copyright (c) 2002 by Thomas Forbriger (IMG Frankfurt)
#
......@@ -26,7 +26,7 @@
#
HEADERS=$(shell find . -name \*.h)
SRC=misc/fortranio.cc misc/commandline.cc misc/ioswap.cc
SRC=misc/fortranio.cc misc/commandline.cc misc/ioswap.cc misc/error.cc
TESTS=$(wildcard tests/*.cc)
FTESTS=$(wildcard tests/*.f)
README=$(shell find . -name README) README.xtra
......@@ -98,6 +98,7 @@ misc.h.strip: misc/misc.h
fortranio.h.strip: misc/fortranio.h
commandline.h.strip: misc/commandline.h
complexio.h.strip: misc/complexio.h
error.h.strip: misc/error.h
# first awk rule assumes that the first non-comment line starts with '#'
# and that the first (copyright) comment end with pattern "^ */"
......@@ -129,7 +130,7 @@ doxyclean: ;/bin/rm -rfv docfull/* docbrief/* docfull docbrief
DOXYSRC=$(README) $(HEADERS) $(SRC)
doc%/html/index.html: doxy%.cfg $(DOXYSRC)
doc%/html/index.html: doxy%.cfg doxyclean $(DOXYSRC)
mkdir -vp $(DOXYWWWPATH)
ln -sfv $(DOXYWWWPATH) $(patsubst doxy%.cfg,doc%,$<)
doxygen $<
......
// this is <README>
// ----------------------------------------------------------------------------
// $Id: README,v 1.5 2002-11-18 15:07:40 forbrig Exp $
// $Id: README,v 1.6 2002-11-27 13:05:40 forbrig Exp $
//
// Copyright (c) 2002 by Thomas Forbriger (IMG Frankfurt)
//
......@@ -18,7 +18,7 @@
\since November 2002
\date November 2002
\version V1.0
$Id: README,v 1.5 2002-11-18 15:07:40 forbrig Exp $
$Id: README,v 1.6 2002-11-27 13:05:40 forbrig Exp $
\section main_aims Aims
......@@ -50,6 +50,14 @@ $Id: README,v 1.5 2002-11-18 15:07:40 forbrig Exp $
This module supports reading and writing of Fortran binary data files.
References to the \ref group_fortranio are collected on a separate page.
\subsection main_module_error Exceptions classes and error handling macros
This modules provides a convenient exception base class and some error
handline preprocessor macros.
\sa tfxx::error
\sa tfxx::error::Exception
\sa error.h
\section main_namespaces Namespaces
We make excessive use of namespaces. This my seem inconvenient at a first
......
/*! \file error.cc
* \brief exceptions and error handling macros (implementation)
*
* ----------------------------------------------------------------------------
*
* $Id: error.cc,v 1.1 2002-11-27 13:05:41 forbrig Exp $
* \author Thomas Forbriger
* \date 27/11/2002
*
* exceptions and error handling macros (implementation)
*
* Copyright (c) 2002 by Thomas Forbriger (IMG Frankfurt)
*
* REVISIONS and CHANGES
* - 27/11/2002 V1.0 Thomas Forbriger
*
* ============================================================================
*/
#define TF_ERROR_CC_VERSION \
"TF_ERROR_CC V1.0 "
#define TF_ERROR_CC_CVSID \
"$Id: error.cc,v 1.1 2002-11-27 13:05:41 forbrig Exp $"
#include <iostream>
#include <tfxx/error.h>
using std::cerr;
using std::endl;
namespace tfxx {
namespace error {
// initialize and instantiate
bool Exception::Mreport_on_construct=true;
// construct from nothing
Exception::Exception():
Mmessage(NULL), Mfile(NULL), Mline(0), Mcondition(NULL)
{ if (Mreport_on_construct) { report(); } }
// construct with message
Exception::Exception(const char* message):
Mmessage(message), Mfile(NULL), Mline(0), Mcondition(NULL)
{ if (Mreport_on_construct) { report(); } }
// construct with message and file info
Exception::Exception(const char* message,
const char* condition):
Mmessage(message), Mfile(NULL), Mline(0), Mcondition(condition)
{ if (Mreport_on_construct) { 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 (Mreport_on_construct) { report(); } }
// switch on
void Exception::report_on_construct()
{
Mreport_on_construct=true;
}
// switch off
void Exception::dont_report_on_construct()
{
Mreport_on_construct=false;
}
// report
void Exception::base_report() const
{
base_report();
}
// report
void Exception::base_report() const
{
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 condition:" << endl
<< " " << Mcondition << endl;
}
}
} // namespace error
} // namespace tfxx
/* ----- END OF error.cc ----- */
/*! \file error.h
* \brief exceptions and error handling macros (prototypes)
*
* ----------------------------------------------------------------------------
*
* $Id: error.h,v 1.1 2002-11-27 13:05:41 forbrig Exp $
* \author Thomas Forbriger
* \date 27/11/2002
*
* exceptions and error handling macros (prototypes)
*
* Copyright (c) 2002 by Thomas Forbriger (IMG Frankfurt)
*
* REVISIONS and CHANGES
* - 27/11/2002 V1.0 Thomas Forbriger
*
* ============================================================================
*/
// include guard
#ifndef TF_ERROR_H_VERSION
#define TF_ERROR_H_VERSION \
"TF_ERROR_H V1.0 "
#define TF_ERROR_H_CVSID \
"$Id: error.h,v 1.1 2002-11-27 13:05:41 forbrig Exp $"
namespace tfxx {
/*! \brief Error handline
*
* You may find the exception base class here.
*/
namespace error {
/*! \brief Base class for exceptions
*/
class Exception
{
public:
Exception();
Exception(const char* message);
Exception(const char* message,
const char* condition);
Exception(const char* message,
const char* file,
const int& line,
const char* condition);
//! 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();
private:
//! Screen report
void base_report() const;
//! Shall we print to cerr at construction time?
static bool Mreport_on_construct;
const char* Mmessage;
const char* Mfile;
const int& Mline;
const char* Mcondition;
}; // class exception
} // namespace error
} // namespace tfxx
/*======================================================================*/
//
// preprocessor macros
// ===================
/*! check an assertion and report by throwing an exception
*
* \param C assert condition
* \param M message of type char*
* \param E exception class to throw
*/
#define TFXX_Xassert(C,M,E) \
if (!(C)) { throw( E ( M , __FILE__, __LINE__, #C )); }
/*! check an assertion and report by throwing an exception
*
* \param C assert condition
* \param M message of type char*
*/
#define TFXX_assert(C,M) TFXX_Xassert( C , M , tfxx::error::Exception )
#endif // TF_ERROR_H_VERSION (includeguard)
/* ----- END OF error.h ----- */
Supports Markdown
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