Team XSockets.NET

Error Handling

Connection Level

To handle errors that the client raises, you can add a handler for the Error event on the connection object.

conn.OnError += (sender, errorArgs) => Console.WriteLine(errorArgs.Exception.Message);

Controller Level

You may also handle errors on individual controller using the OnError event on a specific controller.

conn.Controller("chat").OnError += (sender, errorArgs) => Console.WriteLine(errorArgs.Exception.Message);

To handle errors from method invocations, wrap the code in a try-catch block.

//using XSockets.Core.XSocket;
//using XSockets.Core.XSocket.Helpers;

    var stocks = conn.Controller("stockticker").Invoke<IEnumerable<Stock>>("GetStocks");
    foreach (Stock stock in stocks.Result)
        Console.WriteLine("Symbol: {0} price: {1}", stock.Symbol, stock.Price);
catch (Exception ex)
    Console.WriteLine("Error invoking GetStocks: {0}", ex.Message);

results matching ""

    No results matching ""