如何获取抛出异常的值 [英] How can I get the value or values that throw the exception

查看:102
本文介绍了如何获取抛出异常的值的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

        private void checkRequired(Itcr tmp, string[] reqFields)
        {
            if (reqFields.Any(str => string.IsNullOrEmpty(str)))
            {
                throw new System.InvalidOperationException("A required field is missing");
            }            
        }






www.helixpoint.com



www.helixpoint.com

推荐答案

首先,您应该学习如何使用Visual Studio调试器。您可以在抛出异常的行上放置一个断点,然后从Visual Studio运行该应用程序。

First, you should learn how to use the Visual Studio debugger. You could put a breakpoint on the line that throws the exception and then run the app from Visual Studio.

其次,您的测试只是检查reqFields字符串中是否有任何字符串数组为null或空。如果是,则抛出异常。

Second, your test is simply checking to see if any of the strings in the reqFields string array are null or empty. If they are then the exception is thrown.

这是你的意图吗?


这篇关于如何获取抛出异常的值的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆