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