Permalink
Browse files

Tightened up Exception use.

  • Loading branch information...
1 parent 54bbf4d commit cf987066227f163d0bb684e2523ae82097420a49 Jim Carroll committed Sep 15, 2012
View
11 xbmc/commons/Exception.h
@@ -28,12 +28,19 @@
//---------------------------------------------------------
#include "ilog.h"
+#ifdef __GNUC__
+// The 'this' pointer counts as a parameter on member methods.
+#define XBMCCOMMONS_ATTRIB_EXCEPTION_FORMAT __attribute__((format(printf,2,3)))
+#else
+#define XBMCCOMMONS_ATTRIB_EXCEPTION_FORMAT
+#endif
+
#define XBMCCOMMONS_COPYVARARGS(fmt) va_list argList; va_start(argList, fmt); Set(fmt, argList); va_end(argList)
#define XBMCCOMMONS_STANDARD_EXCEPTION(E) \
class E : public XbmcCommons::Exception \
{ \
public: \
- inline E(const char* message,...) : Exception(#E) { XBMCCOMMONS_COPYVARARGS(message); } \
+ inline E(const char* message,...) XBMCCOMMONS_ATTRIB_EXCEPTION_FORMAT : Exception(#E) { XBMCCOMMONS_COPYVARARGS(message); } \
\
inline E(const E& other) : Exception(other) {} \
}
@@ -72,7 +79,7 @@ namespace XbmcCommons
* This message can be called from the constructor of subclasses.
* It will set the message and log the throwing.
*/
- inline void SetMessage(const char* fmt, ...)
+ inline void SetMessage(const char* fmt, ...) XBMCCOMMONS_ATTRIB_EXCEPTION_FORMAT
{
// calls 'set'
XBMCCOMMONS_COPYVARARGS(fmt);
View
9 xbmc/interfaces/legacy/Addon.cpp
@@ -69,12 +69,9 @@ namespace XBMCAddon
}
else
{
- CStdString errorMessage ("Could not get AddonPtr given a script id of ");
- errorMessage += id;
- errorMessage += ". If you are trying to use 'os.getcwd' to set the path, you cannot do that in a ";
- errorMessage += version.Print();
- errorMessage += " plugin.";
- throw AddonException(errorMessage.c_str());
+ throw AddonException("Could not get AddonPtr given a script id of %s."
+ "If you are trying to use 'os.getcwd' to set the path, you cannot do that in a %s plugin.",
+ id.c_str(), version.Print().c_str());
}
}
View
6 xbmc/interfaces/legacy/Dialog.cpp
@@ -135,7 +135,7 @@ namespace XBMCAddon
std::string mask = maskparam;
VECSOURCES *shares = g_settings.GetSourcesFromType(s_shares);
if (!shares)
- throw WindowException(((std::string("Error: GetSourcesFromType given ") += s_shares) += " is NULL.").c_str());
+ throw WindowException("Error: GetSourcesFromType given %s is NULL.",s_shares.c_str());
if (useFileDirectories && (!maskparam.empty() && !maskparam.size() == 0))
mask += "|.rar|.zip";
@@ -159,7 +159,7 @@ namespace XBMCAddon
CStdStringArray tmpret;
String lmask = mask;
if (!shares)
- throw WindowException(((std::string("Error: GetSourcesFromType given ") += s_shares) += " is NULL.").c_str());
+ throw WindowException("Error: GetSourcesFromType given %s is NULL.",s_shares.c_str());
if (useFileDirectories && (!lmask.empty() && !(lmask.size() == 0)))
lmask += "|.rar|.zip";
@@ -169,7 +169,7 @@ namespace XBMCAddon
else if (type == 2)
CGUIDialogFileBrowser::ShowAndGetImageList(*shares, heading, tmpret);
else
- throw WindowException(((std::string("Error: Cannot retreive multuple directories using browse ") += s_shares) += " is NULL.").c_str());
+ throw WindowException("Error: Cannot retreive multuple directories using browse %s is NULL.",s_shares.c_str());
std::vector<String> valuelist;
int index = 0;
View
14 xbmc/interfaces/legacy/Window.cpp
@@ -190,6 +190,12 @@ namespace XBMCAddon
Control* Window::GetControlById(int iControlId) throw (WindowException)
{
TRACE;
+ CLog::Log(LOGDEBUG,"Window_GetControlById control id: %d",iControlId);
+ if (iControlId == 0)
+ {
+ int i = 12 + 1;
+ }
+
// find in window vector first!!!
// this saves us from creating a complete new control
std::vector<AddonClass::Ref<Control> >::iterator it = vecControls.begin();
@@ -210,9 +216,7 @@ namespace XBMCAddon
if (!pGUIControl)
{
// control does not exist.
- CStdString error;
- error.Format("Non-Existent Control %d",iControlId);
- throw WindowException(error.c_str());
+ throw WindowException("Non-Existent Control %d",iControlId);
}
// allocate a new control with a new reference
@@ -644,10 +648,10 @@ namespace XBMCAddon
{
TRACE;
if(pControl == NULL)
- throw new WindowException("NULL Control passed to WindowBase::addControl");
+ throw WindowException("NULL Control passed to WindowBase::addControl");
if(pControl->iControlId != 0)
- throw new WindowException("Control is already used");
+ throw WindowException("Control is already used");
// lock xbmc GUI before accessing data from it
CSingleLock lock(g_graphicsContext);
View
2 xbmc/interfaces/python/swig.cpp
@@ -119,7 +119,7 @@ namespace PythonBindings
return false;
}
- PythonToCppException::PythonToCppException() : XbmcCommons::UncheckedException("")
+ PythonToCppException::PythonToCppException() : XbmcCommons::UncheckedException(" ")
{
setClassname("PythonToCppException");

0 comments on commit cf98706

Please sign in to comment.