Re: [Alephmodular-devel] Random rumblings on files and errors
Status: Pre-Alpha
Brought to you by:
brefin
|
From: Br'fin <br...@ma...> - 2003-01-30 15:01:15
|
Here is what I have blocked out for error type foo so far. Now I should
mention that this is a model for error handling within a system.
Compare and contrast with the current Marathon error handling system
where an error occurs and it's all handled by various places checking
the game's overall error state in game_error.h/.cpp
Also, I think some of this might apply even if we were using exceptions
to pass errors around. (Heck, the CError class itself that is forming
would seem to make a nice throwable if we did go for exceptions)
///////////////////////////////////////////////////////////////////////
//
// $Id: CErrror.h $
///////////////////////////////////////////////////////////////////////
//
/*
* CErrror.h
* AlephModular
*
* CError defines an interface for classes that can error an go into a
* bad state. For instance, opening a file fails so you need to report
* this back to the calling function.
*
* The basic method this supports is the following:
* A class has a method this_may_fail that returns a boolean (If the
* method needs to return something meaningful like an opened file
* reference, then this is done with out arguments passed by
* reference) If the method is successful, then it returns true.
* Otherwise it returns false and puts the class into a failed state.
* You may get a class's current state to report why an operation
* failed.
*
* Created by Br'fin on Thu Jan 30 2003.
*
*/
#ifndef __CERROR_H
#define __CERROR_H
#include "cseries.h"
#include <string>
class CError;
/*
* IFailable
* Interface
*
* This is an interface to be supported by all classes that may fail.
* For instance, opening a file may fail.
*
*/
class IFailable
{
protected:
/*
* set_error
* arguments:
* an explanatory member of CError that explains the current error
* the IFailable class is responsible for deleting this object
*/
virtual void set_error(const CError*) = 0;
public:
/*
* is_good
* returns:
* true if and only if there is no error state on the object
*/
virtual bool is_good() const = 0;
/*
* get_error
* arguments:
* returns the objects's current error state. Do not free this
* returned state or call clear_error before you use it.
*/
virtual void get_error(const CError* &) const = 0;
/*
* clear_error
* This attempts to clear the error state of the object. This
* is not guarunteed to succeed. If it does succeed then the
* internal CError object is deleted.
* returns:
* true if the error can be cleared. False otherwise
*/
virtual bool clear_error() = 0;
virtual ~IFailable() {} // Required virtual destructor
};
class CError
{
private:
std::string error;
uint16 type;
uint16 error_code;
public:
CError(std::string _reason, uint16 _type, uint16 _code) :
error(_reason), type(_type), error_code(_code) {}
CError(const CError& err) :
error(err.error), type(err.type), error_code(err.error_code) {}
void
get_string(std::string& _string) { _string = error; }
uint16
get_error_code() { return error_code; }
uint16
get_error_type() { return type; }
};
#endif
|