From 010a7f326decdd05a7912238be48f55bc7fb27ee Mon Sep 17 00:00:00 2001 From: illfang Date: Tue, 8 Sep 2015 10:49:33 +0900 Subject: [PATCH] detailed exception string generation for exceptions in injected native functions / properties Conflicts: CefSharp/Internals/JavascriptObjectRepository.cs --- .../JavascriptMethodHandler.cpp | 2 +- .../Internals/JavascriptObjectRepository.cs | 20 +++++++++++++++---- 2 files changed, 17 insertions(+), 5 deletions(-) diff --git a/CefSharp.BrowserSubprocess.Core/JavascriptMethodHandler.cpp b/CefSharp.BrowserSubprocess.Core/JavascriptMethodHandler.cpp index 3c5e8df09..2171893c7 100644 --- a/CefSharp.BrowserSubprocess.Core/JavascriptMethodHandler.cpp +++ b/CefSharp.BrowserSubprocess.Core/JavascriptMethodHandler.cpp @@ -38,7 +38,7 @@ namespace CefSharp } catch (Exception^ ex) { - exception = StringUtils::ToNative(ex->Message); + exception = StringUtils::ToNative(ex->ToString()); } //NOTE: Return true otherwise exception is ignored diff --git a/CefSharp/Internals/JavascriptObjectRepository.cs b/CefSharp/Internals/JavascriptObjectRepository.cs index 7f03955a3..fdee0920a 100644 --- a/CefSharp/Internals/JavascriptObjectRepository.cs +++ b/CefSharp/Internals/JavascriptObjectRepository.cs @@ -118,7 +118,14 @@ namespace CefSharp.Internals parameters = paramList.ToArray(); } - result = method.Function(obj.Value, parameters); + try + { + result = method.Function(obj.Value, parameters); + } + catch (Exception e) + { + throw new InvalidOperationException("Could not execute method: " + name + "(" + String.Join(", ", parameters) + ")" + " - Missing Parameters: " + missingParams, e); + } if(result != null && IsComplexType(result.GetType())) { @@ -134,9 +141,14 @@ namespace CefSharp.Internals return true; } + catch(TargetInvocationException e) + { + var baseException = e.GetBaseException(); + exception = baseException.ToString(); + } catch (Exception ex) { - exception = ex.Message; + exception = ex.ToString(); } return false; @@ -166,7 +178,7 @@ namespace CefSharp.Internals } catch (Exception ex) { - exception = ex.Message; + exception = ex.ToString(); } return false; @@ -194,7 +206,7 @@ namespace CefSharp.Internals } catch (Exception ex) { - exception = ex.Message; + exception = ex.ToString(); } return false;