protected override void OnFaulted(NativeActivityFaultContext faultContext, Exception propagatedException, ActivityInstance propagatedFrom) { Console.WriteLine("OnFaulted: {0}", propagatedException.Message); faultContext.HandleFault(); faultContext.CancelChild(propagatedFrom); Console.WriteLine("OnFaulted: Exception was handled"); }
private void OnTryFaulted(NativeActivityFaultContext faultContext, Exception propagatedException, ActivityInstance propagatedFrom) { // TODO: delete // Write event into the log // This is necessary here because the trace log won't be available later /*var record = new CustomTrackingRecord("OnTryFaulted", System.Diagnostics.TraceLevel.Error) * { * Data = * { * { "Exception", propagatedException }, * { "JobGuid", JobGuid.Get(faultContext) }, * { "UserGuid", UserGuid.Get(faultContext) }, * } * }; * faultContext.Track(record); */ // Handle exception int r = retries.Get(faultContext); retries.Set(faultContext, ++r); faultContext.CancelChild(propagatedFrom); faultContext.HandleFault(); // Run the finally block before doing anything else if (Finally != null) { faultContext.ScheduleActivity(this.Finally, OnFinallyComplete, OnFinallyFaulted); } else { OnFinallyComplete(faultContext, null); } // If retry is possible, if (r < MaxRetries.Get(faultContext)) { // absorb error faultContext.HandleFault(); faultContext.ScheduleActivity(this.Try, OnTryComplete, OnTryFaulted); } else { // fault throw propagatedException; } }
/// <summary> /// Invoked when an error occurs in the body. /// </summary> /// <param name="context"></param> /// <param name="propagatedException"></param> /// <param name="propagatedFrom"></param> void OnBodyFaulted(NativeActivityFaultContext context, Exception propagatedException, ActivityInstance propagatedFrom) { var state = this.state.Get(context); // discover if exception is handled, if so cancel children and record var c = FindCatch(propagatedException); if (c != null) { context.CancelChild(propagatedFrom); state.CaughtException = propagatedException; context.HandleFault(); } }
/// <summary> /// Respond to the fault callback, used for all scheduled activities. /// </summary> /// <param name="context">The activity context.</param> /// <param name="exception">An exception which was thrown by the activity.</param> /// <param name="instance">The current instance of the activity.</param> private void OnOperationFault(NativeActivityFaultContext context, Exception exception, ActivityInstance instance) { // Mark the fault handled, or else this activity will throw and will not contine after this method returns. context.HandleFault(); // TODO: Make this logging dependent on the operation configuration LogBuildError(context, string.Format("AzureAsyncOperation Fault {0} during execution of {1}\r\n{2}", exception.GetType().Name, instance.Activity.GetType().Name, exception.Message)); LogBuildMessage(context, exception.StackTrace, BuildMessageImportance.High); // Cancel the running activity context.CancelChild(instance); // Notify that an exception has been caught // The CompletionCallback will be called because we handled the exception. // This makes a better design choice to do any scheduling or further logic there. this.AzureActivityExceptionCaught.Set(context, true); }
void OnExceptionFromTry(NativeActivityFaultContext context, Exception propagatedException, ActivityInstance propagatedFrom) { if (propagatedFrom.IsCancellationRequested) { if (TD.TryCatchExceptionDuringCancelationIsEnabled()) { TD.TryCatchExceptionDuringCancelation(this.DisplayName); } // The Try activity threw an exception during Cancel; abort the workflow context.Abort(propagatedException); context.HandleFault(); } else { Catch catchHandler = FindCatch(propagatedException); if (catchHandler != null) { if (TD.TryCatchExceptionFromTryIsEnabled()) { TD.TryCatchExceptionFromTry(this.DisplayName, propagatedException.GetType().ToString()); } context.CancelChild(propagatedFrom); TryCatchState state = this.state.Get(context); // If we are not supposed to persist exceptions, enter our noPersistScope ExceptionPersistenceExtension extension = context.GetExtension <ExceptionPersistenceExtension>(); if ((extension != null) && !extension.PersistExceptions) { NoPersistProperty noPersistProperty = (NoPersistProperty)context.Properties.FindAtCurrentScope(NoPersistProperty.Name); if (noPersistProperty != null) { // The property will be exited when the activity completes or aborts. noPersistProperty.Enter(); } } state.CaughtException = context.CreateFaultContext(); context.HandleFault(); } } }
private void ActionFailed(NativeActivityFaultContext faultContext, Exception propagatedexception, ActivityInstance propagatedfrom) { Int32 currentAttemptCount = _attemptCount.Get(faultContext); Int32 maxAttempts = MaxAttempts.Get(faultContext); Type[] exceptionType = ExceptionType.Get(faultContext); //Increment and track the count currentAttemptCount++; _attemptCount.Set(faultContext, currentAttemptCount); if (currentAttemptCount >= maxAttempts) { // There are no further attempts to make return; } if (ShouldRetryAction(exceptionType, propagatedexception) == false) { _log.Error("Will only retry exception of type '" + exceptionType.ToCSV() + "'. Unhandled type of '" + propagatedexception.GetType().FullName + "' was found.", propagatedexception); return; } faultContext.CancelChild(propagatedfrom); faultContext.HandleFault(); TimeSpan retryInterval = _delayOverrideForUnitTests == null?RetryInterval.Get(faultContext) : _delayOverrideForUnitTests.Value; _log.Debug("Retrying in " + retryInterval.TotalSeconds + " seconds due to " + propagatedexception.GetType().FullName + ". " + currentAttemptCount + " of " + maxAttempts); if (retryInterval == TimeSpan.Zero) { ExecuteAttempt(faultContext); } else { // We are going to wait before trying again _delayDuration.Set(faultContext, retryInterval); faultContext.ScheduleActivity( _internalDelay, DelayCompleted); } }
private void OnExceptionFromTry(NativeActivityFaultContext context, Exception propagatedException, System.Activities.ActivityInstance propagatedFrom) { if (propagatedFrom.IsCancellationRequested) { if (TD.TryCatchExceptionDuringCancelationIsEnabled()) { TD.TryCatchExceptionDuringCancelation(base.DisplayName); } context.Abort(propagatedException); context.HandleFault(); } else if (this.FindCatch(propagatedException) != null) { if (TD.TryCatchExceptionFromTryIsEnabled()) { TD.TryCatchExceptionFromTry(base.DisplayName, propagatedException.GetType().ToString()); } context.CancelChild(propagatedFrom); this.state.Get(context).CaughtException = context.CreateFaultContext(); context.HandleFault(); } }
private void ActionFailed(NativeActivityFaultContext faultcontext, Exception propagatedexception, ActivityInstance propagatedfrom) { Int32 currentAttemptCount = _attemptCount.Get(faultcontext); currentAttemptCount++; _attemptCount.Set(faultcontext, currentAttemptCount); Int32 maxAttempts = MaxAttempts.Get(faultcontext); if (currentAttemptCount >= maxAttempts) { // There are no further attempts to make return; } if (ShouldRetryAction(ExceptionType, propagatedexception) == false) { return; } faultcontext.CancelChild(propagatedfrom); faultcontext.HandleFault(); TimeSpan retryInterval = RetryInterval.Get(faultcontext); if (retryInterval == TimeSpan.Zero) { ExecuteAttempt(faultcontext); } else { // We are going to wait before trying again _delayDuration.Set(faultcontext, retryInterval); faultcontext.ScheduleActivity(_internalDelay, DelayCompleted); } }