Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add 'Windows.UI.Xaml.*' exception types #1705

Merged
merged 4 commits into from
Aug 6, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -18,10 +18,14 @@
name="AuthoringWuxTest.MultipleInterfaceMappingClass"
threadingModel="both"
xmlns="urn:schemas-microsoft-com:winrt.v1" />
<activatableClass
name="AuthoringWuxTest.XamlExceptionTypes"
threadingModel="both"
xmlns="urn:schemas-microsoft-com:winrt.v1" />
</file>
<compatibility xmlns="urn:schemas-microsoft-com:compatibility.v1">
<application>
<maxversiontested Id="10.0.18226.0"/>
</application>
</compatibility>
</assembly>
</assembly>
5 changes: 5 additions & 0 deletions src/Tests/AuthoringWuxConsumptionTest/test.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,11 @@ TEST(AuthoringWuxTest, PropertyChanged)
EXPECT_TRUE(eventTriggered);
}

TEST(AuthoringWuxTest, XamlExceptionTypes)
{
EXPECT_TRUE(XamlExceptionTypes::VerifyExceptionTypes());
}

int main(int argc, char** argv)
{
::testing::InitGoogleTest(&argc, argv);
Expand Down
18 changes: 18 additions & 0 deletions src/Tests/AuthoringWuxTest/Program.cs
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
using System.Collections.Generic;
using System.Collections.Specialized;
using System.ComponentModel;
using WinRT;

#pragma warning disable CA1416

Expand Down Expand Up @@ -168,4 +169,21 @@ void IList.RemoveAt(int index)
_list.RemoveAt(index);
}
}

public static class XamlExceptionTypes
{
public static bool VerifyExceptionTypes()
{
const int E_XAMLPARSEFAILED = unchecked((int)0x802B000A);
const int E_LAYOUTCYCLE = unchecked((int)0x802B0014);
const int E_ELEMENTNOTENABLED = unchecked((int)0x802B001E);
const int E_ELEMENTNOTAVAILABLE = unchecked((int)0x802B001F);

return
ExceptionHelpers.GetExceptionForHR(E_XAMLPARSEFAILED)?.GetType() == typeof(Windows.UI.Xaml.Markup.XamlParseException) &&
ExceptionHelpers.GetExceptionForHR(E_LAYOUTCYCLE)?.GetType() == typeof(Windows.UI.Xaml.LayoutCycleException) &&
ExceptionHelpers.GetExceptionForHR(E_ELEMENTNOTENABLED)?.GetType() == typeof(Windows.UI.Xaml.Automation.ElementNotEnabledException) &&
ExceptionHelpers.GetExceptionForHR(E_ELEMENTNOTAVAILABLE)?.GetType() == typeof(Windows.UI.Xaml.Automation.ElementNotAvailableException);
}
}
}
117 changes: 117 additions & 0 deletions src/WinRT.Runtime/ExceptionHelpers.Microsoft.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,117 @@
// Copyright (c) Microsoft Corporation.
// Licensed under the MIT License.

using System;

namespace Microsoft.UI.Xaml
{
namespace Automation
{
#if EMBED
internal
#else
public
#endif
class ElementNotAvailableException : Exception
{
public ElementNotAvailableException()
: base("The element is not available.")
{
HResult = WinRT.ExceptionHelpers.E_ELEMENTNOTAVAILABLE;
}

public ElementNotAvailableException(string message)
: base(message)
{
HResult = WinRT.ExceptionHelpers.E_ELEMENTNOTAVAILABLE;
}

public ElementNotAvailableException(string message, Exception innerException)
: base(message, innerException)
{
HResult = WinRT.ExceptionHelpers.E_ELEMENTNOTAVAILABLE;
}
}

#if EMBED
internal
#else
public
#endif
class ElementNotEnabledException : Exception
{
public ElementNotEnabledException()
: base("The element is not enabled.")
{
HResult = WinRT.ExceptionHelpers.E_ELEMENTNOTENABLED;
}

public ElementNotEnabledException(string message)
: base(message)
{
HResult = WinRT.ExceptionHelpers.E_ELEMENTNOTENABLED;
}

public ElementNotEnabledException(string message, Exception innerException)
: base(message, innerException)
{
HResult = WinRT.ExceptionHelpers.E_ELEMENTNOTENABLED;
}
}
}
namespace Markup
{

#if EMBED
internal
#else
public
#endif
class XamlParseException : Exception
{
public XamlParseException()
: base("XAML parsing failed.")
{
HResult = WinRT.ExceptionHelpers.E_XAMLPARSEFAILED;
}

public XamlParseException(string message)
: base(message)
{
HResult = WinRT.ExceptionHelpers.E_XAMLPARSEFAILED;
}

public XamlParseException(string message, Exception innerException)
: base(message, innerException)
{
HResult = WinRT.ExceptionHelpers.E_XAMLPARSEFAILED;
}
}
}

#if EMBED
internal
#else
public
#endif
class LayoutCycleException : Exception
{
public LayoutCycleException()
: base("A cycle occurred while laying out the GUI.")
{
HResult = WinRT.ExceptionHelpers.E_LAYOUTCYCLE;
}

public LayoutCycleException(string message)
: base(message)
{
HResult = WinRT.ExceptionHelpers.E_LAYOUTCYCLE;
}

public LayoutCycleException(string message, Exception innerException)
: base(message, innerException)
{
HResult = WinRT.ExceptionHelpers.E_LAYOUTCYCLE;
}
}
}
118 changes: 118 additions & 0 deletions src/WinRT.Runtime/ExceptionHelpers.Windows.net5.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,118 @@
// Copyright (c) Microsoft Corporation.
// Licensed under the MIT License.

using System;
Sergio0694 marked this conversation as resolved.
Show resolved Hide resolved

namespace Windows.UI.Xaml
{
namespace Automation
{
#if EMBED
internal
#else
public
#endif
class ElementNotAvailableException : Exception
{
public ElementNotAvailableException()
: base("The element is not available.")
{
HResult = WinRT.ExceptionHelpers.E_ELEMENTNOTAVAILABLE;
}

public ElementNotAvailableException(string message)
: base(message)
{
HResult = WinRT.ExceptionHelpers.E_ELEMENTNOTAVAILABLE;
}

public ElementNotAvailableException(string message, Exception innerException)
: base(message, innerException)
{
HResult = WinRT.ExceptionHelpers.E_ELEMENTNOTAVAILABLE;
}
}

#if EMBED
internal
#else
public
#endif
class ElementNotEnabledException : Exception
{
public ElementNotEnabledException()
: base("The element is not enabled.")
{
HResult = WinRT.ExceptionHelpers.E_ELEMENTNOTENABLED;
}

public ElementNotEnabledException(string message)
: base(message)
{
HResult = WinRT.ExceptionHelpers.E_ELEMENTNOTENABLED;
}

public ElementNotEnabledException(string message, Exception innerException)
: base(message, innerException)
{
HResult = WinRT.ExceptionHelpers.E_ELEMENTNOTENABLED;
}
}
}

namespace Markup
{

#if EMBED
internal
#else
public
#endif
class XamlParseException : Exception
{
public XamlParseException()
: base("XAML parsing failed.")
{
HResult = WinRT.ExceptionHelpers.E_XAMLPARSEFAILED;
}

public XamlParseException(string message)
: base(message)
{
HResult = WinRT.ExceptionHelpers.E_XAMLPARSEFAILED;
}

public XamlParseException(string message, Exception innerException)
: base(message, innerException)
{
HResult = WinRT.ExceptionHelpers.E_XAMLPARSEFAILED;
}
}
}

#if EMBED
internal
#else
public
#endif
class LayoutCycleException : Exception
{
public LayoutCycleException()
: base("A cycle occurred while laying out the GUI.")
{
HResult = WinRT.ExceptionHelpers.E_LAYOUTCYCLE;
}

public LayoutCycleException(string message)
: base(message)
{
HResult = WinRT.ExceptionHelpers.E_LAYOUTCYCLE;
}

public LayoutCycleException(string message, Exception innerException)
: base(message, innerException)
{
HResult = WinRT.ExceptionHelpers.E_LAYOUTCYCLE;
}
}
}
Loading
Loading