public void Execute() { IMyoCommandResult result = null; try { result = _command(); if (result == null) { // TODO: replace all of this by contracts once supported. throw new NullReferenceException("The result of a MyoCommandDelegate cannot be null."); } if (result.Result == MyoResult.Success) { return; } throw CreateMyoException(result); } finally { if (result != null) { _myoErrorHandlerDriver.FreeMyoError(result.ErrorHandle); } } }
private Exception CreateMyoException(IMyoCommandResult myoCommandResult) { var errorMessage = _myoErrorHandlerDriver.GetErrorString(myoCommandResult.ErrorHandle); return(myoCommandResult.Result == MyoResult.ErrorInvalidArgument ? (Exception) new ArgumentException(errorMessage) : (Exception) new InvalidOperationException(errorMessage)); }
private Exception CreateMyoException(IMyoCommandResult myoCommandResult) { Contract.Requires<ArgumentNullException>(myoCommandResult != null, "myoCommandResult"); Contract.Requires<ArgumentException>(myoCommandResult.Result != MyoResult.Success, "The result code must not be MyoResult.Success."); var errorMessage = _myoErrorHandlerDriver.GetErrorString(myoCommandResult.ErrorHandle); return myoCommandResult.Result == MyoResult.ErrorInvalidArgument ? (Exception)new ArgumentException(errorMessage) : (Exception)new InvalidOperationException(errorMessage); }
private Exception CreateMyoException(IMyoCommandResult myoCommandResult) { ////Contract.Requires<ArgumentNullException>(myoCommandResult != null, "myoCommandResult"); ////Contract.Requires<ArgumentException>(myoCommandResult.Result != MyoResult.Success, "The result code must not be MyoResult.Success."); var errorMessage = _myoErrorHandlerDriver.GetErrorString(myoCommandResult.ErrorHandle); return(myoCommandResult.Result == MyoResult.ErrorInvalidArgument ? (Exception) new ArgumentException(errorMessage) : (Exception) new InvalidOperationException(errorMessage)); }