58 lines
1.8 KiB
C#
58 lines
1.8 KiB
C#
using System;
|
|
using System.Threading.Tasks;
|
|
using Hi.Common;
|
|
using Hi.Common.Messages;
|
|
|
|
namespace Sample.Common
|
|
{
|
|
/// <summary>
|
|
/// Demonstrates common message and exception handling patterns in HiAPI applications
|
|
/// </summary>
|
|
/// <remarks>
|
|
/// ### Source Code
|
|
/// [!code-csharp[SampleCode](~/../Hi.Sample/Common/DemoMessageAndExceptionHandling.cs)]
|
|
/// </remarks>
|
|
public static class DemoMessageAndExceptionHandling
|
|
{
|
|
/// <summary>
|
|
/// Demonstrates normal message handling
|
|
/// </summary>
|
|
internal static void DemoNormalMessages()
|
|
{
|
|
#region Normal_Messages
|
|
MessageKit.AddMessage("Operation completed successfully.");
|
|
MessageKit.AddWarning("Please check your input.");
|
|
#endregion
|
|
}
|
|
/// <summary>
|
|
/// Demonstrates exception handling in synchronous code
|
|
/// </summary>
|
|
internal static void DemoSynchronousExceptionHandling()
|
|
{
|
|
#region Sync_Exception
|
|
try
|
|
{
|
|
// Your code here
|
|
throw new NotImplementedException("Demo exception");
|
|
}
|
|
catch (Exception ex)
|
|
{
|
|
ExceptionUtil.ShowException(ex, null);
|
|
}
|
|
#endregion
|
|
}
|
|
/// <summary>
|
|
/// Demonstrates exception handling in asynchronous code
|
|
/// </summary>
|
|
internal static async Task DemoAsynchronousExceptionHandling()
|
|
{
|
|
#region Async_Exception
|
|
await Task.Run(() =>
|
|
{
|
|
// Your async operation here
|
|
throw new NotImplementedException("Demo async exception");
|
|
}).ShowIfCatched(null);
|
|
#endregion
|
|
}
|
|
}
|
|
} |