Reduced GUI's exception usage (=> shortened debug-mode start time by a couple of seconds)

This was SVN commit r1494.
This commit is contained in:
Ykkrosh 2004-12-13 12:07:12 +00:00
parent 114f3f1513
commit 80b1876b77
4 changed files with 172 additions and 184 deletions

View File

@ -578,7 +578,7 @@ void CGUI::AddObject(IGUIObject* pObject)
GUI<CGUI*>::RecurseObject(0, pObject, &IGUIObject::SetGUI, this);
// Add child to base object
m_BaseObject->AddChild(pObject);
m_BaseObject->AddChild(pObject); // can throw
// Cache tree
GUI<>::RecurseObject(0, pObject, &IGUIObject::UpdateCachedSize);
@ -1301,13 +1301,8 @@ void CGUI::Xeromyces_ReadObject(XMBElement Element, CXeromyces* pFile, IGUIObjec
}
// Try setting the value
try
if (object->SetSetting(pFile->getAttributeString(attr.Name), (CStr)attr.Value) != PS_OK)
{
object->SetSetting(pFile->getAttributeString(attr.Name), (CStr)attr.Value);
}
catch (PS_RESULT e)
{
UNUSED(e);
ReportParseError("Can't set \"%s\" to \"%s\"", pFile->getAttributeString(attr.Name).c_str(), CStr(attr.Value).c_str());
// This is not a fatal error
@ -1327,17 +1322,12 @@ void CGUI::Xeromyces_ReadObject(XMBElement Element, CXeromyces* pFile, IGUIObjec
CStrW caption (Element.getText());
if (caption.Length())
{
try
{
// Set the setting caption to this
object->SetSetting("caption", caption);
}
catch (PS_RESULT)
{
// There is no harm if the object didn't have a "caption"
}
}
//

View File

@ -238,16 +238,16 @@ bool IGUIObject::SettingExists(const CStr& Setting) const
{ \
type _Value; \
if (!GUI<type>::ParseString(Value, _Value)) \
throw PS_FAIL; \
return PS_FAIL; \
\
GUI<type>::SetSetting(this, Setting, _Value); \
}
void IGUIObject::SetSetting(const CStr& Setting, const CStr& Value)
PS_RESULT IGUIObject::SetSetting(const CStr& Setting, const CStr& Value)
{
if (!SettingExists(Setting))
{
throw PS_FAIL;
return PS_FAIL;
}
// Get setting
@ -268,10 +268,14 @@ void IGUIObject::SetSetting(const CStr& Setting, const CStr& Value)
ADD_TYPE(EVAlign)
else
{
throw PS_FAIL;
return PS_FAIL;
}
return PS_OK;
}
#undef ADD_TYPE
PS_RESULT IGUIObject::GetSettingType(const CStr& Setting, EGUISettingType &Type) const
{
if (!SettingExists(Setting))
@ -357,20 +361,15 @@ void IGUIObject::LoadStyle(const SGUIStyle &Style)
for (cit = Style.m_SettingsDefaults.begin(); cit != Style.m_SettingsDefaults.end(); ++cit)
{
// Try set setting in object
try
{
SetSetting(cit->first, cit->second);
}
// It doesn't matter if it fail, it's not suppose to be able to set every setting.
// since it's generic.
catch (PS_RESULT e)
{
UNUSED(e);
// The beauty with styles is that it can contain more settings
// than exists for the objects using it. So if the SetSetting
// fails, don't care.
}
}
}
float IGUIObject::GetBufferedZ() const

View File

@ -259,9 +259,9 @@ public:
* @param Setting Setting by name
* @param Value Value to set to
*
* @throws PS_RESULT
* @return PS_RESULT (PS_OK if successful)
*/
void SetSetting(const CStr& Setting, const CStr& Value);
PS_RESULT SetSetting(const CStr& Setting, const CStr& Value);
/**
* Retrieves the type of a named setting.

View File

@ -207,9 +207,10 @@ JSBool JSI_IGUIObject::setProperty(JSContext* cx, JSObject* obj, jsval id, jsval
{
CStr propValue = JS_GetStringBytes(JS_ValueToString(cx, *vp));
e->SetName(propValue);
return JS_TRUE;
}
else
{
EGUISettingType Type;
if (e->GetSettingType(propName, Type) != PS_OK)
{
@ -217,8 +218,6 @@ JSBool JSI_IGUIObject::setProperty(JSContext* cx, JSObject* obj, jsval id, jsval
return JS_TRUE;
}
try
{
switch (Type)
{
@ -290,7 +289,11 @@ JSBool JSI_IGUIObject::setProperty(JSContext* cx, JSObject* obj, jsval id, jsval
{
if (JSVAL_IS_STRING(*vp))
{
e->SetSetting(propName, JS_GetStringBytes(JS_ValueToString(cx, *vp)) );
if (e->SetSetting(propName, JS_GetStringBytes(JS_ValueToString(cx, *vp))) != PS_OK)
{
JS_ReportError(cx, "Invalid value for setting '%s'", propName.c_str());
return JS_FALSE;
}
}
else if (JSVAL_IS_OBJECT(*vp) && JS_GetClass(JSVAL_TO_OBJECT(*vp)) == &JSI_GUISize::JSI_class)
{
@ -323,7 +326,11 @@ JSBool JSI_IGUIObject::setProperty(JSContext* cx, JSObject* obj, jsval id, jsval
{
if (JSVAL_IS_STRING(*vp))
{
e->SetSetting(propName, JS_GetStringBytes(JS_ValueToString(cx, *vp)) );
if (e->SetSetting(propName, JS_GetStringBytes(JS_ValueToString(cx, *vp))) != PS_OK)
{
JS_ReportError(cx, "Invalid value for setting '%s'", propName.c_str());
return JS_FALSE;
}
}
else if (JSVAL_IS_OBJECT(*vp) && JS_GetClass(JSVAL_TO_OBJECT(*vp)) == &JSI_GUIColor::JSI_class)
{
@ -352,15 +359,7 @@ JSBool JSI_IGUIObject::setProperty(JSContext* cx, JSObject* obj, jsval id, jsval
JS_ReportError(cx, "Setting '%s' uses an unimplemented type", propName.c_str());
break;
}
}
// Catch failed calls to SetSetting (the string and templated versions)
catch (PS_RESULT)
{
JS_ReportError(cx, "Invalid value for setting '%s'", propName.c_str());
return JS_FALSE;
}
}
return JS_TRUE;
}