Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
tree: 296d6d5203
Fetching contributors…

Cannot retrieve contributors at this time

38 lines (30 sloc) 1.243 kb
/* This file is (c) 2008-2012 Konstantin Isakov <ikm@goldendict.org>
* Part of GoldenDict. Licensed under GPLv3 or later, see the LICENSE file */
#ifndef __EX_HH_INCLUDED__
#define __EX_HH_INCLUDED__
#include <string>
/// A way to declare an exception class fast
/// Do like this:
/// DEF_EX( exErrorInFoo, "An error in foo encountered", std::exception )
/// DEF_EX( exFooNotFound, "Foo was not found", exErrorInFoo )
#define DEF_EX( exName, exDescription, exParent ) \
class exName: public exParent { \
public: \
virtual const char * what() const throw() { return (exDescription); } \
virtual ~exName() throw() {} };
/// Same as DEF_EX, but takes a runtime string argument, which gets concatenated
/// with the description.
///
/// DEF_EX_STR( exCantOpen, "can't open file", std::exception )
/// ...
/// throw exCantOpen( "example.txt" );
///
/// what() would return "can't open file example.txt"
#define DEF_EX_STR( exName, exDescription, exParent ) \
class exName: public exParent { \
std::string value; \
public: \
exName( std::string const & value_ ): value( std::string( exDescription ) + " " + value_ ) {} \
virtual const char * what() const throw() { return value.c_str(); } \
virtual ~exName() throw() {} };
#endif
Jump to Line
Something went wrong with that request. Please try again.