From fe96061b003b7064b3e17c468a8851784890f7b8 Mon Sep 17 00:00:00 2001 From: brain Date: Sun, 19 Feb 2006 15:09:24 +0000 Subject: More exception throwing in constructors git-svn-id: http://svn.inspircd.org/repository/trunk/inspircd@3245 e03df62e-2008-0410-955e-edbf42e46eb7 --- src/modules/extra/m_filter_pcre.cpp | 19 +++++++++++++------ src/modules/m_censor.cpp | 1 + src/modules/m_filter.cpp | 1 + src/modules/m_helpop.cpp | 17 +++++++++++++---- 4 files changed, 28 insertions(+), 10 deletions(-) (limited to 'src') diff --git a/src/modules/extra/m_filter_pcre.cpp b/src/modules/extra/m_filter_pcre.cpp index f6ec64d6c..fe3d721d4 100644 --- a/src/modules/extra/m_filter_pcre.cpp +++ b/src/modules/extra/m_filter_pcre.cpp @@ -28,6 +28,15 @@ using namespace std; #include "modules.h" #include "helperfuncs.h" +class FilterPCREException +{ + public: + virtual char* GetReason() + { + return "Could not find definition in your config file!"; + } +}; + /* $ModDesc: m_filter with regexps */ /* $CompileFlags: -I/usr/local/include */ /* $LinkerFlags: -L/usr/local/lib -lpcre */ @@ -56,9 +65,8 @@ class ModuleFilterPCRE : public Module MyConf = new ConfigReader(filterfile); if ((filterfile == "") || (!MyConf->Verify())) { - printf("Error, could not find definition in your config file!\n"); - log(DEFAULT,"Error, could not find definition in your config file!"); - return; + FilterPCREException e; + throw(e); } Srv->Log(DEFAULT,std::string("m_filter_pcre: read configuration from ")+filterfile); @@ -156,10 +164,9 @@ class ModuleFilterPCRE : public Module MyConf = new ConfigReader(filterfile); if ((filterfile == "") || (!MyConf->Verify())) { + FilterPCREException e; // bail if the user forgot to create a config file - printf("Error, could not find definition in your config file!"); - log(DEFAULT,"Error, could not find definition in your config file!"); - return; + throw(e); } Srv->Log(DEFAULT,std::string("m_filter_pcre: read configuration from ")+filterfile); diff --git a/src/modules/m_censor.cpp b/src/modules/m_censor.cpp index ed576302b..0d18ac1e4 100644 --- a/src/modules/m_censor.cpp +++ b/src/modules/m_censor.cpp @@ -27,6 +27,7 @@ using namespace std; class CensorException : public ModuleException { + public: virtual char* GetReason() { return "Could not find definition in your config file!"; diff --git a/src/modules/m_filter.cpp b/src/modules/m_filter.cpp index 59fbed596..c8d5633ff 100644 --- a/src/modules/m_filter.cpp +++ b/src/modules/m_filter.cpp @@ -31,6 +31,7 @@ using namespace std; class FilterException : public ModuleException { + public: virtual char* GetReason() { return "Could not find definition in your config file!"; diff --git a/src/modules/m_helpop.cpp b/src/modules/m_helpop.cpp index 9af6d6dc4..3272b3580 100644 --- a/src/modules/m_helpop.cpp +++ b/src/modules/m_helpop.cpp @@ -160,6 +160,15 @@ void sendtohelpop(userrec *src, int pcnt, char **params) Srv->SendToModeMask("oh",WM_AND,line); } +class HelpopException +{ + private: + std::string err; + public: + HelpopException(std::string message) : err(message) { } + virtual char* GetReason() { return (char*)err.c_str(); } +}; + class ModuleHelpop : public Module { private: @@ -192,8 +201,8 @@ class ModuleHelpop : public Module if (h_file == "") { helpop = NULL; - log(DEFAULT,"m_helpop: Helpop file not Specified."); - return; + HelpopException e("Missing helpop file"); + throw(e); } helpop = new ConfigReader(h_file); @@ -201,8 +210,8 @@ class ModuleHelpop : public Module (helpop->ReadValue("nohelpo", "line1", 0) == "") || (helpop->ReadValue("start", "line1", 0) == "")) { - log(DEFAULT,"m_helpop: Helpop file is missing important entries. Please check the example conf."); - return; + HelpopException e("m_helpop: Helpop file is missing important entries. Please check the example conf."); + throw(e); } } -- cgit v1.2.3