本文整理汇总了C#中System.Exception.NotNull方法的典型用法代码示例。如果您正苦于以下问题:C# Exception.NotNull方法的具体用法?C# Exception.NotNull怎么用?C# Exception.NotNull使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类System.Exception
的用法示例。
在下文中一共展示了Exception.NotNull方法的5个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: Handle
/// <summary>
/// Handles all exceptions in the chain
/// </summary>
/// <param name="exceptionToHandle">The exception to handle</param>
/// <returns>Whether or not a rethrow is recommended</returns>
public bool Handle(Exception exceptionToHandle)
{
exceptionToHandle.NotNull(nameof(exceptionToHandle));
return RethrowRecommended(
ExecuteHandlerChain(exceptionToHandle, Guid.NewGuid()));
}
示例2: MethodReturn
/// <summary>
/// Parameterized constructor.
/// </summary>
public MethodReturn(IMethodInvocation originalInvocation, Exception exception)
{
originalInvocation.NotNull("originalInvocation");
exception.NotNull("exception");
this.InvocationContext = originalInvocation.InvocationContext;
this.Exception = exception;
this.Outputs = new ParameterCollection(new object[0], new ParameterInfo[0], delegate { return false; });
}
示例3: HandleException
/// <summary>
/// Checks if there is a policy entry that matches
/// the type of the specified exception,
/// and if so, invokes the handlers associated with that entry
/// </summary>
/// <param name="exceptionToHandle">The exception to handle</param>
/// <returns>True when rethrowing an exception is recommended</returns>
public bool HandleException(Exception exceptionToHandle)
{
exceptionToHandle.NotNull(nameof(exceptionToHandle));
var entry = GetPolicyEntry(exceptionToHandle);
return entry.IsNull()
? true
: entry.Handle(exceptionToHandle);
}
示例4: HandleException
/// <summary>
/// Handles the specified exception object according to the rules configured for policyName
/// </summary>
/// <param name="exceptionToHandle">The exception to handle</param>
/// <param name="policyName">The name of the policy to handle</param>
/// <returns>True if rethrowing an exception is recommended; otherwise, false</returns>
/// <example>
/// The following code shows the usage of the
/// exception handling framework.
/// <code>
/// try
/// {
/// DoWork();
/// }
/// catch (Exception e)
/// {
/// if (exceptionManager.HandleException(e, name)) throw;
/// }
/// </code>
/// </example>
public bool HandleException(
Exception exceptionToHandle,
string policyName = "default")
{
exceptionToHandle.NotNull(nameof(exceptionToHandle));
policyName.NotNullOrEmpty(nameof(policyName));
IExceptionPolicyDefinition exceptionPolicy;
if (!_exceptionPolicies.TryGetValue(policyName, out exceptionPolicy))
throw new InvalidOperationException("Exception policy not found");
return exceptionPolicy.HandleException(exceptionToHandle);
}
示例5: HandleException
private static bool HandleException(
Exception exceptionToHandle,
string policyName = "default")
{
exceptionToHandle.NotNull(nameof(exceptionToHandle));
policyName.NotNullOrEmpty(nameof(policyName));
return ExceptionManager
.HandleException(exceptionToHandle, policyName);
}