将异常传递给方法并引发此类异常

时间:2018-10-11 08:27:02

标签: c# exception-handling

如何将异常传递给方法并在此方法中抛出该类型的异常>

这是我的尝试:

    public static void AgainstNull<T, D>(T value, string paramName, D exception, string message)
        where T : class
        where D : Exception
    {
        if (value == null)
        {
            throw new exception(paramName, message);
        }
    }

和用法:

        User user = await this.userManager.FindByNameAsync(assignRoleModel.Username);
        Guard.AgainstNull(user, nameof(user), ArgumentNullException, ErrorMessages.FindUserByNameError);

0 个答案:

没有答案