From f5b2ce92d302063d1fc063c29ea4f8e809ba673d Mon Sep 17 00:00:00 2001 From: Per Lundberg Date: Sat, 11 May 2013 09:30:44 +0300 Subject: [PATCH] Implemented exception handling if the property cannot be read. Not 100% sure about this one, but in some way it feels best to propagate a CLR exception into the exception output variable. --- CefSharp/PropertyAccessor.h | 21 +++++++++++++++------ 1 file changed, 15 insertions(+), 6 deletions(-) diff --git a/CefSharp/PropertyAccessor.h b/CefSharp/PropertyAccessor.h index 35cfd3a55..75335875e 100644 --- a/CefSharp/PropertyAccessor.h +++ b/CefSharp/PropertyAccessor.h @@ -21,22 +21,31 @@ namespace CefSharp CefString& exception) override { auto unmanagedWrapper = static_cast(object->GetUserData().get()); - String^ clrName = toClr(name); + auto clrName = toClr(name); PropertyInfo^ property; if (unmanagedWrapper->Properties->TryGetValue(clrName, property)) { - Object^ wrappedObject = unmanagedWrapper->Get(); - if(wrappedObject == nullptr) + auto wrappedObject = unmanagedWrapper->Get(); + + if (wrappedObject == nullptr) { exception = "Binding's CLR object is null."; return true; } - Object^ clrValue = property->GetValue(wrappedObject, nullptr); + try + { + auto clrValue = property->GetValue(wrappedObject, nullptr); - retval = convertToCef(clrValue, nullptr); - return true; + retval = convertToCef(clrValue, nullptr); + return true; + } + catch (Exception^ e) + { + exception = toNative(e->Message); + return true; + } } else {