Compare commits
No commits in common. "master" and "1.0.0" have entirely different histories.
3 changed files with 16 additions and 23 deletions
|
|
@ -19,7 +19,7 @@ Example
|
|||
#include <iostream>
|
||||
#include <iomanip>
|
||||
|
||||
#include <exceptions/exceptions.h>
|
||||
#include "exceptions.h"
|
||||
|
||||
// Use this macro to build up your hierarchy of exceptions
|
||||
EXCEPTION( Exception, Existential_Observation );
|
||||
|
|
|
|||
|
|
@ -5,7 +5,7 @@
|
|||
#include <sstream>
|
||||
#include <stdexcept>
|
||||
|
||||
#include "exceptions/exceptions.h"
|
||||
#include "exceptions.h"
|
||||
|
||||
// Use this macro to build up your hierarchy of exceptions
|
||||
EXCEPTION( Exception, Existential_Observation );
|
||||
|
|
|
|||
|
|
@ -1,6 +1,5 @@
|
|||
#pragma once
|
||||
#ifndef EXCEPTIONS_H
|
||||
#define EXCEPTIONS_H
|
||||
#ifndef __EXCEPTIONS_H__
|
||||
#define __EXCEPTIONS_H__
|
||||
|
||||
#include <string>
|
||||
#include <sstream>
|
||||
|
|
@ -20,7 +19,7 @@
|
|||
EXCEPTION(Exception,Buddhist_Observation);
|
||||
creates an new exception class "Buddhist_Observation", derived from the base "Exception"
|
||||
*/
|
||||
#define EXCEPTION(Super,Current) class Current : public Super {public: Current ( const std::string & desc, const std::string & func="?", const std::string & f="?", const int l=-1, const std::string & n=#Current ) : Super (desc,func,f,l,n) {} }
|
||||
#define EXCEPTION(Super,Current) class Current : public Super {public: Current ( const std::string & desc, const std::string & func="?", const std::string & f="?", const int l=-1 ) : Super (desc,func,f,l) {name = #Current;} }
|
||||
|
||||
|
||||
/** A shortcut to throw an exception without having to type ",E_INFOS"
|
||||
|
|
@ -36,6 +35,8 @@
|
|||
class Exception : public std::exception
|
||||
{
|
||||
protected:
|
||||
//! Name of the current exception class
|
||||
std::string name;
|
||||
|
||||
//! Description of the exception
|
||||
std::string description;
|
||||
|
|
@ -49,12 +50,6 @@ protected:
|
|||
//! Line where the exception has been raised
|
||||
int line;
|
||||
|
||||
//! Name of the current exception class
|
||||
std::string name;
|
||||
|
||||
//! Assembled message
|
||||
std::string message;
|
||||
|
||||
public:
|
||||
//! Constructor of the exception
|
||||
/*!
|
||||
|
|
@ -64,23 +59,21 @@ public:
|
|||
Use the E_INFOS macro to raise the exception, for example :
|
||||
throw( Exception( "Shit evolves", E_INFOS );
|
||||
*/
|
||||
Exception( const std::string & desc, const std::string & func, const std::string & f, const int l, const std::string & n = "Exception" )
|
||||
: description(desc), function(func), file(f), line(l), name(n)
|
||||
{
|
||||
std::ostringstream msg;
|
||||
msg << "<" << name << "> " << description << "\t\t" << function << " @ " << file << ":" << line << "";
|
||||
message = msg.str();
|
||||
}
|
||||
Exception( const std::string & desc, const std::string & func, const std::string & f, const int l )
|
||||
: description(desc), function(func), file(f), line(l) {}
|
||||
|
||||
//! The destructor is not allowed to throw exceptions
|
||||
virtual ~Exception() noexcept {}
|
||||
virtual ~Exception() throw () {}
|
||||
|
||||
//! The method to use for printing the complete description of the exception
|
||||
const char* what() const noexcept
|
||||
std::string what()
|
||||
{
|
||||
return message.c_str();
|
||||
std::ostringstream msg;
|
||||
msg << description << " (<" << name << "> in " << function << " at " << file << ":" << line << ")";
|
||||
|
||||
return msg.str();
|
||||
}
|
||||
};
|
||||
|
||||
#endif // EXCEPTIONS_H
|
||||
#endif // __EXCEPTIONS_H__
|
||||
|
||||
Loading…
Add table
Add a link
Reference in a new issue