X-Git-Url: https://git.netwichtig.de/gitweb/?a=blobdiff_plain;f=include%2Fmodules.h;h=8c37a8cc28ae312cf45edd810eac4874f5344d32;hb=6279a01bf5b6da48bedfdfe2d39dde69e46ae401;hp=e1fb37621b292cea16a86d1c63931466f603d8fb;hpb=2a9b0cdd30113ab4926f4b68350d619c015c89a3;p=user%2Fhenk%2Fcode%2Finspircd.git diff --git a/include/modules.h b/include/modules.h index e1fb37621..8c37a8cc2 100644 --- a/include/modules.h +++ b/include/modules.h @@ -97,7 +97,7 @@ typedef std::deque chanuserlist; { \ modules[_i]->x ; \ } \ - catch (ModuleException modexcept) \ + catch (ModuleException& modexcept) \ { \ log(DEBUG,"Module exception cought: %s",modexcept.GetReason()); \ } \ @@ -122,7 +122,7 @@ typedef std::deque chanuserlist; break; \ } \ } \ - catch (ModuleException modexcept) \ + catch (ModuleException& modexcept) \ { \ log(DEBUG,"Module exception cought: %s",modexcept.GetReason()); \ } \ @@ -287,14 +287,35 @@ class ExtMode : public classbase }; +/** This class can be used on its own to represent an exception, or derived to represent a module-specific exception. + * When a module whishes to abort, e.g. within a constructor, it should throw an exception using ModuleException or + * a class derived from ModuleException. If a module throws an exception during its constructor, the module will not + * be loaded. If this happens, the error message returned by ModuleException::GetReason will be displayed to the user + * attempting to load the module, or dumped to the console if the ircd is currently loading for the first time. + */ class ModuleException { + private: + /** Holds the error message to be displayed + */ + std::string err; public: - virtual ModuleException() {}; + /** Default constructor, just uses the error mesage 'Module threw an exception'. + */ + ModuleException() : err("Module threw an exception") {} + /** This constructor can be used to specify an error message before throwing. + */ + ModuleException(std::string message) : err(message) {} + /** This destructor solves world hunger, cancels the world debt, and causes the world to end. + * Actually no, it does nothing. Never mind. + */ virtual ~ModuleException() {}; + /** Returns the reason for the exception. + * The module should probably put something informative here as the user will see this upon failure. + */ virtual char *GetReason() { - return "Module threw an exception"; + return (char*)err.c_str(); } }; @@ -329,6 +350,7 @@ class Module : public classbase /** Default constructor * Creates a module class. * @param Me An instance of the Server class which can be saved for future use + * \exception ModuleException Throwing this class, or any class derived from ModuleException, causes loading of the module to abort. */ Module(Server* Me); @@ -1717,6 +1739,10 @@ class Server : public classbase virtual void DelSocket(InspSocket* sock); virtual void RehashServer(); + + virtual long GetChannelCount(); + + virtual chanrec* GetChannelIndex(long index); };