From 74f5253a366cefa5222a813f4ed349db93c08acc Mon Sep 17 00:00:00 2001 From: SignpostMarv Date: Thu, 16 Aug 2012 15:32:20 +0100 Subject: attempt to handle InvalidCastException in a manner similar to Second Life --- .../ScriptEngine/Shared/Api/Implementation/LSL_Api.cs | 4 ++++ OpenSim/Region/ScriptEngine/Shared/LSL_Types.cs | 15 +++++++++++++-- 2 files changed, 17 insertions(+), 2 deletions(-) (limited to 'OpenSim/Region') diff --git a/OpenSim/Region/ScriptEngine/Shared/Api/Implementation/LSL_Api.cs b/OpenSim/Region/ScriptEngine/Shared/Api/Implementation/LSL_Api.cs index b7b5e8e..255fc8e 100644 --- a/OpenSim/Region/ScriptEngine/Shared/Api/Implementation/LSL_Api.cs +++ b/OpenSim/Region/ScriptEngine/Shared/Api/Implementation/LSL_Api.cs @@ -7674,6 +7674,10 @@ namespace OpenSim.Region.ScriptEngine.Shared.Api } } } + catch (InvalidCastException e) + { + ShoutError(e.Message); + } finally { if (positionChanged) diff --git a/OpenSim/Region/ScriptEngine/Shared/LSL_Types.cs b/OpenSim/Region/ScriptEngine/Shared/LSL_Types.cs index d848b2a..562433d 100644 --- a/OpenSim/Region/ScriptEngine/Shared/LSL_Types.cs +++ b/OpenSim/Region/ScriptEngine/Shared/LSL_Types.cs @@ -560,12 +560,23 @@ namespace OpenSim.Region.ScriptEngine.Shared else if (m_data[itemIndex] is LSL_Types.LSLString) return new LSLInteger(m_data[itemIndex].ToString()); else - throw new InvalidCastException(); + throw new InvalidCastException(string.Format( + "{0} expected but {1} given", + typeof(LSL_Types.LSLInteger).Name, + m_data[itemIndex] != null ? + m_data[itemIndex].GetType().Name : "null")); } public LSL_Types.Vector3 GetVector3Item(int itemIndex) { - return (LSL_Types.Vector3)m_data[itemIndex]; + if(m_data[itemIndex] is LSL_Types.Vector3) + return (LSL_Types.Vector3)m_data[itemIndex]; + else + throw new InvalidCastException(string.Format( + "{0} expected but {1} given", + typeof(LSL_Types.Vector3).Name, + m_data[itemIndex] != null ? + m_data[itemIndex].GetType().Name : "null")); } public LSL_Types.Quaternion GetQuaternionItem(int itemIndex) -- cgit v1.1