Table of Contents

Class DemoMessageAndExceptionHandling

Namespace
Sample.Common
Assembly
Hi.Sample.dll

Demonstrates common message and exception handling patterns in HiAPI applications

public static class DemoMessageAndExceptionHandling
Inheritance
DemoMessageAndExceptionHandling
Inherited Members

Remarks

Source Code

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
            MessageHost.AddMessage("Operation completed successfully.");
            MessageHost.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
        }
    }
}