diff --git a/Xamarin.Forms.Xaml.UnitTests/DesignTimeLoaderTests.cs b/Xamarin.Forms.Xaml.UnitTests/DesignTimeLoaderTests.cs
index d450bc5a8..0023d0ac8 100644
--- a/Xamarin.Forms.Xaml.UnitTests/DesignTimeLoaderTests.cs
+++ b/Xamarin.Forms.Xaml.UnitTests/DesignTimeLoaderTests.cs
@@ -564,23 +564,22 @@ namespace Xamarin.Forms.Xaml.UnitTests
+
";
-
var exceptions = new List();
Xamarin.Forms.Internals.ResourceLoader.ExceptionHandler = exceptions.Add;
Assert.DoesNotThrow(() => XamlLoader.Create(xaml, true));
Assert.That(exceptions.Count, Is.GreaterThan(1));
- }
+ }
- [Test]
+ [Test]
public void CanResolveRootNode()
{
string assemblyName = null;
string clrNamespace = null;
string typeName = null;
-
XamlLoader.FallbackTypeResolver = (fallbackTypeInfos, type) =>
{
assemblyName = fallbackTypeInfos?[1].AssemblyName;
diff --git a/Xamarin.Forms.Xaml/ExpandMarkupsVisitor.cs b/Xamarin.Forms.Xaml/ExpandMarkupsVisitor.cs
index 0296222f3..6e60dcfaa 100644
--- a/Xamarin.Forms.Xaml/ExpandMarkupsVisitor.cs
+++ b/Xamarin.Forms.Xaml/ExpandMarkupsVisitor.cs
@@ -78,17 +78,28 @@ namespace Xamarin.Forms.Xaml
if (expression.StartsWith("{}", StringComparison.Ordinal))
return new ValueNode(expression.Substring(2), null);
- if (expression[expression.Length - 1] != '}')
- throw new Exception("Expression must end with '}'");
+ if (expression[expression.Length - 1] != '}') {
+ var ex = new XamlParseException("Expression must end with '}'", xmlLineInfo);
+ if (Context.ExceptionHandler != null) {
+ Context.ExceptionHandler(ex);
+ return null;
+ }
+ throw ex;
+ }
- int len;
- string match;
- if (!MarkupExpressionParser.MatchMarkup(out match, expression, out len))
+ if (!MarkupExpressionParser.MatchMarkup(out var match, expression, out var len))
throw new Exception();
- expression = expression.Substring(len).TrimStart();
- if (expression.Length == 0)
- throw new Exception("Expression did not end in '}'");
+ expression = expression.Substring(len).TrimStart();
+ if (expression.Length == 0) {
+ var ex = new XamlParseException("Expression did not end in '}'", xmlLineInfo);
+ if (Context.ExceptionHandler != null)
+ {
+ Context.ExceptionHandler(ex);
+ return null;
+ }
+ throw ex;
+ }
var serviceProvider = new XamlServiceProvider(node, Context);
serviceProvider.Add(typeof (IXmlNamespaceResolver), nsResolver);