summaryrefslogtreecommitdiff
path: root/include/Exceptions.h
diff options
context:
space:
mode:
Diffstat (limited to 'include/Exceptions.h')
-rw-r--r--include/Exceptions.h28
1 files changed, 25 insertions, 3 deletions
diff --git a/include/Exceptions.h b/include/Exceptions.h
index b630def..470ee45 100644
--- a/include/Exceptions.h
+++ b/include/Exceptions.h
@@ -17,7 +17,7 @@
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
*/
-/* $Id: Exceptions.h,v 1.39 2004-11-27 23:45:10 pixel Exp $ */
+/* $Id: Exceptions.h,v 1.40 2004-11-28 12:20:10 pixel Exp $ */
#ifndef __EXCEPTIONS_H__
#define __EXCEPTIONS_H__
@@ -43,6 +43,12 @@ struct ugly_string;
void xfree(unsigned char *&);
+//! The Base class, that everybody should use.
+/*!
+ This base class should be derivated for every single class you create. That
+ way, common functions will be overloaded and safe to use (like malloc)12~
+*/
+
class Base {
public:
virtual ~Base() {};
@@ -61,6 +67,7 @@ class Base {
}
static int pipe(int * p, int flag = 0);
static pid_t fork();
+ //! This wrapper will call the xexit function.
static void exit(int);
static void printm(int level, const ugly_string &, ...);
static void printm(int level, const char *, ...);
@@ -72,11 +79,18 @@ class Base {
static std::vector<String> context;
};
+//! Every exception class should inherit from this one.
+/*!
+ This generic class should be handled from the main, so that the software
+ can exit nicely if an exception is thrown, with a built-in message.
+*/
class GeneralException : public Base {
public:
+ //! The constructor has to provide a string describing the exception.
GeneralException(String);
GeneralException(const GeneralException &);
~GeneralException();
+ //! This should only be used by the exception manager in order to display what went wrong.
const char * GetMsg() const;
protected:
@@ -90,6 +104,7 @@ void * xmalloc(size_t) throw (GeneralException);
void * xrealloc(void *, size_t);
int xpipe(int *, int = 0) throw (GeneralException);
pid_t xfork() throw (GeneralException);
+//! This will simply throw the Exit exception.
void xexit(int) throw (GeneralException);
void xexception(const String &) throw (GeneralException);
@@ -130,10 +145,17 @@ class TaskSwitch : public GeneralException {
TaskSwitch();
};
+//! This exception can be thrown anyway, in order to exit nicely the software.
+/*!
+ My suggestion when using this exception, is to add a special manager, in order to
+ handle clean up, in the same manner as the atexit function.
+*/
class Exit : public GeneralException {
public:
- Exit(int);
- int GetCode();
+ //! The provided code should be the exit code.
+ Exit(int code);
+ //! Fetches the exit code out of the Exit exception.
+ int GetCode();
private:
int code;
};