private static IActor FailOnException(Exception exception, IActor actor, IActorMessage actorMessage, IActorInvocation actorInvocation) { Assert.Fail(); return(actor); }
private static IActor SendMessageToDurableQueueForLaterDelivery(Exception exception, IActor actor, IActorMessage actorMessage, IActorInvocation actorInvocation) { ++failCount; durableTasksToWaitOn.Add(Telegraph.Instance.Ask(new Messages.SendMsgToDurableQueue(actorMessage))); return(actor); }
static IActor HandleExceptionByCancelingTask(Exception ex, IActor actor, IActorMessage msg, IActorInvocation invoker) { if (msg.Message is string) { System.Console.WriteLine("Null Reference Exception Handled for " + (string)msg.Message); } if (null != msg.Status) { msg.Status.SetCanceled(); } return(null); }
static IActor HandleExceptionWithPrintingIt(Exception ex, IActor actor, IActorMessage msg, IActorInvocation invoker) { if (msg.Message is byte[]) { System.Console.WriteLine(ex.GetType() + " Handled for " + Encoding.ASCII.GetString((byte[])msg.Message)); } if (null != msg.Status) { msg.Status.SetException(ex); } // NOTE we could instantiate a new actor here using the original Func that registered the action. This is done through the passed in invoker // and return it for future processing. return(null); }
private void CheckForAndRunExceptionHandler(Exception ex, IActor actor, IActorMessage msg) { List <Exception> exceptions = new List <Exception>(); if (null != ex) { exceptions.Add(ex); } try { Exception foundEx = null; Func <Exception, IActor, IActorMessage, IActorInvocation, IActor> handler; handler = this.FindExceptionHandler(_exceptionTypeToHandler, ex, actor, msg, out foundEx); if (null != foundEx && foundEx != ex) { exceptions.Add(foundEx); } if (null == handler) { return; } IActorInvocation invoker = null; IActor newActor = handler.Invoke(foundEx, actor, msg, invoker); if (null == newActor || newActor == actor) { return; } _messageTypeToActor.TryUpdate(msg.GetType(), newActor, actor); } catch (NotImplementedException ne) { exceptions.Add(ne); Console.Error.WriteLine(ne); System.Diagnostics.Debug.Assert(false); throw; } catch (Exception exp) { exceptions.Add(exp); Console.Error.WriteLine(exp); //TODO fail hard!!! System.Diagnostics.Debug.Assert(false); } finally { if (null != msg.Status && exceptions.Any()) { try { msg.Status.SetException(exceptions); } catch (System.InvalidOperationException) { // The underlying System.Threading.Tasks.Task`1 is already in one of the three final // states: System.Threading.Tasks.TaskStatus.RanToCompletion, System.Threading.Tasks.TaskStatus.Faulted, // or System.Threading.Tasks.TaskStatus.Canceled. } } } }