Skip to content

Commit

Permalink
Remove errorMsg from CallMethod arguments. Refs #970
Browse files Browse the repository at this point in the history
This way it will only get constructed if an error is actually going
to occur.
  • Loading branch information
martyngigg committed Apr 15, 2013
1 parent 2977daf commit dfdcc85
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 12 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -80,7 +80,7 @@ namespace Mantid { namespace PythonInterface {
* @param errorMsg :: An error message to pass to the generated exception
* @return The value of the function or the default value if it does not exist
*/
static ResultType dispatchWithException(PyObject *self, const char * funcName, const char * errorMsg)
static ResultType dispatchWithException(PyObject *self, const char * funcName)
{
GlobalInterpreterLock gil;
if(Environment::typeHasAttribute(self, funcName))
Expand All @@ -96,7 +96,10 @@ namespace Mantid { namespace PythonInterface {
}
else
{
throw std::runtime_error(errorMsg);
std::ostringstream os;
os << self->ob_type->tp_name << " has no function named '" << funcName << "'\n"
<< "Check the function exists and that its first argument is self.";
throw std::runtime_error(os.str());
}
return ResultType();
}
Expand Down Expand Up @@ -136,7 +139,7 @@ namespace Mantid { namespace PythonInterface {
* @param errorMsg :: An error message if the method does not exist
* @return The value of the function or the default value if it does not exist
*/
static void dispatchWithException(PyObject *self, const char * funcName, const char * errorMsg)
static void dispatchWithException(PyObject *self, const char * funcName)
{
GlobalInterpreterLock gil;
if(Environment::typeHasAttribute(self, funcName))
Expand All @@ -152,7 +155,10 @@ namespace Mantid { namespace PythonInterface {
}
else
{
throw std::runtime_error(errorMsg);
std::ostringstream os;
os << self->ob_type->tp_name << " has no function named '" << funcName << "'\n"
<< "Check the function exists and that its first argument is self.";
throw std::runtime_error(os.str());
}
}
};
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -69,10 +69,7 @@ namespace Mantid
*/
void AlgorithmWrapper::init()
{
std::ostringstream os;
os << "Python algorithm '" << this->name()
<< "' does not define the PyInit function, cannot initialize.";
CallMethod_NoArg<void>::dispatchWithException(getSelf(), "PyInit", os.str().c_str());
CallMethod_NoArg<void>::dispatchWithException(getSelf(), "PyInit");
}

/**
Expand All @@ -81,10 +78,8 @@ namespace Mantid
*/
void AlgorithmWrapper::exec()
{
std::ostringstream os;
os << "Python algorithm '" << this->name()
<< "' does not define the PyExec function, cannot execute.";
CallMethod_NoArg<void>::dispatchWithException(getSelf(), "PyExec", os.str().c_str());

CallMethod_NoArg<void>::dispatchWithException(getSelf(), "PyExec");
}

}
Expand Down

0 comments on commit dfdcc85

Please sign in to comment.