*/
class CoreExport CoreException : public std::exception
{
- public:
+ protected:
/** Holds the error message to be displayed
*/
const std::string err;
/** Source of the exception
*/
const std::string source;
- /** Default constructor, just uses the error mesage 'Core threw an exception'.
- */
- CoreException() : err("Core threw an exception"), source("The core") {}
+
+ public:
/** This constructor can be used to specify an error message before throwing.
+ * @param message Human readable error message
*/
CoreException(const std::string &message) : err(message), source("The core") {}
/** This constructor can be used to specify an error message before throwing,
* and to specify the source of the exception.
+ * @param message Human readable error message
+ * @param src Source of the exception
*/
CoreException(const std::string &message, const std::string &src) : err(message), source(src) {}
/** This destructor solves world hunger, cancels the world debt, and causes the world to end.
*/
virtual ~CoreException() throw() {};
/** Returns the reason for the exception.
- * The module should probably put something informative here as the user will see this upon failure.
+ * @return Human readable description of the error
*/
- virtual const char* GetReason()
- {
- return err.c_str();
- }
+ const std::string& GetReason() const { return err; }
- virtual const char* GetSource()
- {
- return source.c_str();
- }
+ /** Returns the source of the exception
+ * @return Source of the exception
+ */
+ const std::string& GetSource() const { return source; }
};
class Module;
} \
catch (CoreException& modexcept) \
{ \
- ServerInstance->Logs->Log("MODULE", LOG_DEFAULT, "Exception caught: %s",modexcept.GetReason()); \
+ ServerInstance->Logs->Log("MODULE", LOG_DEFAULT, "Exception caught: " + modexcept.GetReason()); \
} \
} \
} while (0);
} \
catch (CoreException& except_ ## n) \
{ \
- ServerInstance->Logs->Log("MODULE", LOG_DEFAULT, "Exception caught: %s", (except_ ## n).GetReason()); \
+ ServerInstance->Logs->Log("MODULE", LOG_DEFAULT, "Exception caught: " + (except_ ## n).GetReason()); \
} \
} \
} while(0)
}
catch (Exception& ex)
{
- ServerInstance->Logs->Log("RESOLVER", LOG_DEBUG, std::string(ex.GetReason()));
+ ServerInstance->Logs->Log(MODNAME, LOG_DEBUG, ex.GetReason());
return;
}
catch (DNS::Exception& e)
{
delete res_forward;
- ServerInstance->Logs->Log("RESOLVER", LOG_DEBUG, "Error in resolver: %s",e.GetReason());
+ ServerInstance->Logs->Log(MODNAME, LOG_DEBUG, "Error in resolver: " + e.GetReason());
bound_user->WriteNotice("*** There was an internal error resolving your host, using your IP address (" + bound_user->GetIPString() + ") instead.");
dl->set(bound_user, 0);
{
this->dnsLookup.set(user, 0);
delete res_reverse;
- ServerInstance->Logs->Log("USERS", LOG_DEBUG, "Error in resolver: %s", e.GetReason());
+ ServerInstance->Logs->Log(MODNAME, LOG_DEBUG, "Error in resolver: " + e.GetReason());
ServerInstance->stats->statsDnsBad++;
}
}
if (vsnret > 0 && static_cast<unsigned>(vsnret) < formatBuffer.size())
{
- return &formatBuffer[0];
+ break;
}
formatBuffer.resize(formatBuffer.size() * 2);
}
- throw CoreException();
+ return &formatBuffer[0];
}
const char* InspIRCd::Format(const char* formatString, ...)
catch (CoreException& modexcept)
{
ServerInstance->Logs->Log("SOCKET", LOG_DEFAULT, "%s threw an exception: %s",
- modexcept.GetSource(), modexcept.GetReason());
+ modexcept.GetSource().c_str(), modexcept.GetReason().c_str());
}
DelIOHook();
}
catch (CoreException& modexcept)
{
ServerInstance->Logs->Log("SOCKET", LOG_DEFAULT, "%s threw an exception: %s",
- modexcept.GetSource(), modexcept.GetReason());
+ modexcept.GetSource().c_str(), modexcept.GetReason().c_str());
return;
}
if (rv > 0)
catch (CoreException& modexcept)
{
ServerInstance->Logs->Log("SOCKET", LOG_DEBUG, "%s threw an exception: %s",
- modexcept.GetSource(), modexcept.GetReason());
+ modexcept.GetSource().c_str(), modexcept.GetReason().c_str());
}
}
#ifndef DISABLE_WRITEV
catch (CoreException& ex)
{
ServerInstance->Logs->Log("SOCKET", LOG_DEFAULT, "Caught exception in socket processing on FD %d - '%s'",
- fd, ex.GetReason());
+ fd, ex.GetReason().c_str());
SetError(ex.GetReason());
}
if (!error.empty())
waiting.set(user, count - 1);
delete r;
if (cmd.notify)
- ServerInstance->SNO->WriteToSnoMask('a', "Connecting user %s detected as using CGI:IRC (%s), but I could not resolve their hostname; %s", user->nick.c_str(), user->host.c_str(), ex.GetReason());
+ ServerInstance->SNO->WriteToSnoMask('a', "Connecting user %s detected as using CGI:IRC (%s), but I could not resolve their hostname; %s", user->nick.c_str(), user->host.c_str(), ex.GetReason().c_str());
}
}
}
catch (ModuleException& e)
{
- throw ModuleException(e.err + " (while creating mode from " + tag->getTagLocation() + ")");
+ throw ModuleException(e.GetReason() + " (while creating mode from " + tag->getTagLocation() + ")");
}
}
}
catch (DNS::Exception &ex)
{
delete r;
- ServerInstance->Logs->Log(MODNAME, LOG_DEBUG, std::string(ex.GetReason()));
+ ServerInstance->Logs->Log(MODNAME, LOG_DEBUG, ex.GetReason());
}
if (user->quitting)
}
catch (ModuleException& e)
{
- ServerInstance->Logs->Log(MODNAME, LOG_DEBUG, "Error when unserializing filter: " + std::string(e.GetReason()));
+ ServerInstance->Logs->Log(MODNAME, LOG_DEBUG, "Error when unserializing filter: " + e.GetReason());
}
}
}
}
catch (ModuleException &e)
{
- ServerInstance->Logs->Log(MODNAME, LOG_DEFAULT, "Error in regular expression '%s': %s", freeform.c_str(), e.GetReason());
+ ServerInstance->Logs->Log(MODNAME, LOG_DEFAULT, "Error in regular expression '%s': %s", freeform.c_str(), e.GetReason().c_str());
return std::make_pair(false, e.GetReason());
}
return std::make_pair(true, "");
}
catch (ModuleException &e)
{
- ServerInstance->Logs->Log(MODNAME, LOG_DEFAULT, "Error in regular expression '%s': %s", pattern.c_str(), e.GetReason());
+ ServerInstance->Logs->Log(MODNAME, LOG_DEFAULT, "Error in regular expression '%s': %s", pattern.c_str(), e.GetReason().c_str());
}
}
}
}
catch (ModuleException &e)
{
- ServerInstance->Logs->Log(MODNAME, LOG_DEBUG, "Ident exception: %s", e.GetReason());
+ ServerInstance->Logs->Log(MODNAME, LOG_DEBUG, "Ident exception: " + e.GetReason());
}
}
}
catch (ModuleException &e)
{
- ServerInstance->SNO->WriteToSnoMask('a',"Could not add RLINE: %s", e.GetReason());
+ ServerInstance->SNO->WriteToSnoMask('a',"Could not add RLINE: " + e.GetReason());
}
if (r)
}
catch (ModuleException &e)
{
- ServerInstance->SNO->WriteToSnoMask('d',"Unable to ADDLINE type %s from %s: %s", params[0].c_str(), setter.c_str(), e.GetReason());
+ ServerInstance->SNO->WriteToSnoMask('d',"Unable to ADDLINE type %s from %s: %s", params[0].c_str(), setter.c_str(), e.GetReason().c_str());
return CMD_FAILURE;
}
xl->SetCreateTime(ConvToInt(params[3]));
catch (DNS::Exception& e)
{
delete snr;
- ServerInstance->SNO->WriteToSnoMask('l', "CONNECT: Error connecting \002%s\002: %s.",x->Name.c_str(), e.GetReason());
+ ServerInstance->SNO->WriteToSnoMask('l', "CONNECT: Error connecting \002%s\002: %s.",x->Name.c_str(), e.GetReason().c_str());
ConnectServer(y, false);
}
}
}
catch (CoreException& modexcept)
{
- ServerInstance->Logs->Log("SOCKET", LOG_DEBUG, "%s threw an exception: %s", modexcept.GetSource(), modexcept.GetReason());
+ ServerInstance->Logs->Log("SOCKET", LOG_DEBUG, "%s threw an exception: %s", modexcept.GetSource().c_str(), modexcept.GetReason().c_str());
}
}