StreamLink for Silverlight
IExceptionHandler Interface
StreamLink for SilverlightCaplin.StreamLinkIExceptionHandler
Definition of the interface that receives exceptions generated by StreamLink on its own threads.
Declaration Syntax
C#Visual BasicVisual C++
public interface IExceptionHandler
Public Interface IExceptionHandler
public interface class IExceptionHandler
Members
All MembersMethods



IconMemberDescription
HandleException(Exception)
Handles a StreamLink exception.

Remarks

It is recommended that you implement the IExceptionHandler interface, so your application can handle exceptions generated by StreamLink. Such an exception indicates that the internal state of the StreamLink library can no longer be relied upon as being correct.

Important

Your exception handler should shut the application down gracefully, since the only way to recover from the exception is to restart the application. There is no need to log the exception in the handler because StreamLink logs it through the ILogger before passing it to the IExceptionHandler.

The application must register the IExceptionHandler with StreamLink by setting the ExceptionHandler property of the StreamLink object. If you do not implement and register an IExceptionHandler, StreamLink will continue to run when it encounters an internal exception, but its behaviour will be unpredictable.

CopyC#
using System;
using System.Collections.Generic;
using System.Text;

using Caplin.StreamLink;
using Caplin.StreamLink.Authentication;

namespace StreamLinkExamples.Basics
{
    /// <summary>
    /// Example inner class that implements IExceptionHandler and
    /// a an outline of how it may be used.
    /// </summary>
    public class SettingUpAnExceptionHandler
    {
        /// <summary>
        /// An example of how to set up a very basic exception handler.
        /// </summary>
        public static void SettingUpAnExceptionHandlerExample()
        {
            // Create a basic StreamLink instance
            StreamLink myStreamLink = new StreamLink();

            // Set up the exception handler
            myStreamLink.ExceptionHandler = new ExampleExceptionHandler();
        }

        /// <summary>
        /// Example class that implements IExceptionHandler
        /// </summary>
        private class ExampleExceptionHandler: IExceptionHandler
        {
            /// <summary>
            /// IExceptionHandler method called when an unexpected exception
            /// occurs within the StreamLink library.
            /// </summary>
            /// <param name="ex">The exception.</param>
            public void HandleException(Exception ex)
            {
                // Clean up application

                // Warn the user about the error and that the application is
                // to close

                // Close the application
            }
        }
    }
}
Thread Safety

The IExceptionHandler methods are not called on a dedicated worker thread. They are called directly from a thread running within the StreamLink library.

Assembly: Caplin.StreamLink.Silverlight (Module: Caplin.StreamLink.Silverlight) Version: 5.0.13.0 (5.0.13.0)