diff Implab/AbstractEvent.cs @ 186:75103928da09 ref20160224

working on cancelation and error handling
author cin
date Tue, 19 Apr 2016 00:50:14 +0300
parents 822aab37b107
children d6fe09f5592c
line wrap: on
line diff
--- a/Implab/AbstractEvent.cs	Mon Apr 18 16:41:17 2016 +0300
+++ b/Implab/AbstractEvent.cs	Tue Apr 19 00:50:14 2016 +0300
@@ -77,19 +77,14 @@
         /// <param name="error">Исключение возникшее при выполнении операции</param>
         /// <exception cref="InvalidOperationException">Данное обещание уже выполнено</exception>
         protected void SetError(Exception error) {
-            while (error is PromiseTransientException)
-                error = error.InnerException;
-
-            var isCancel = error is OperationCanceledException;
-            
             if (BeginTransit()) {
-                m_error = isCancel ? error.InnerException : error;
-                CompleteTransit(isCancel ? CANCELLED_STATE : REJECTED_STATE);
+                m_error = error;
+                CompleteTransit(REJECTED_STATE);
 
                 Signal();
             } else {
                 WaitTransition();
-                if (!isCancel || m_state == SUCCEEDED_STATE)
+                if (m_state == SUCCEEDED_STATE)
                     throw new InvalidOperationException("The promise is already resolved");
             }
         }
@@ -140,11 +135,11 @@
                 case SUCCEEDED_STATE:
                     return;
                 case CANCELLED_STATE:
-                    throw new OperationCanceledException();
+                    throw new OperationCanceledException("The operation has been cancelled", m_error);
                 case REJECTED_STATE:
                     throw new TargetInvocationException(m_error);
                 default:
-                    throw new ApplicationException(String.Format("Invalid promise state {0}", m_state));
+                    throw new ApplicationException(String.Format("The promise state {0} is invalid", m_state));
             }
         }
         #endregion