异常处理错误 [英] exception handeling error

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

问题描述

从内容页面的catch块返回时,出现''Exception was unhandelled by user code'' 的错误消息
我的代码是,

I am getting error as ''Exception was unhandelled by user code'' on returning from content page''s catch block
my code is as,

Public Void Vcf()
{
if (StateName1.Text == string.Empty || StateName1.Text == StringConstants.select ||
            StateName1.SelectedValue.ToString() == StringConstants.select)
{
    try
    {
        throw new  Exception(ErrorConstants.selectTheState);

    }
    catch (Exception exception)
    {
        throw exception;
    }
}
}



< -------------------在这里获取异常错误.从这里,我的异常消息应该转到带有异常消息的母版页的catch块,如




<---------------Here im gettting the exception error. From here my exception message should have to go to master page''s catch block with exception message which is as,


private object CallContentFunction(string methodName, params object[] parameters)    
{
        try        
         {    Type contentType = this.Page.GetType();                
              System.Reflection.MethodInfo mi = contentType.GetMethod(methodName);                
              if (mi == null) 
                return null;                
              return mi.Invoke(this.Page, parameters);           
         }
        catch (Exception exception)  
        {           
          throw exception;        
        }    
}

推荐答案



This

try
{
    throw new  Exception(ErrorConstants.selectTheState);
}
catch (Exception exception)
{
    throw exception;
}



等效于:



is equivalent to this:

try
{
    throw new  Exception(ErrorConstants.selectTheState);
}
catch {
    throw;
}



并为此:



and to this:

throw new  Exception(ErrorConstants.selectTheState);



就是这样,没有道理.您没有捕获到异常.来考虑一下,你不应该.

您可能打算将try块放在下面:



That''s it, makes no sense. You did not catch the exception. Come to think about, you should not.

You probably mean to put under the try block this:

if (StateName1.Text == string.Empty || StateName1.Text == StringConstants.select ||
StateName1.SelectedValue.ToString() == StringConstants.select)



在这里,StateName1.SelectedValue可以为null,StateName1不应为null(并且很可能不是).因此,您不应假定已选择某项,它会在尝试调用ToString时引发异常.

考虑:



Here, StateName1.SelectedValue could be null, StateName1 should not be null (and most likely it is not). So, you should not assume something is selected, it throws exception at the attempt to call ToString.

Consider:

if (StateName1.Text == string.Empty ||
    StateName1.Text == StringConstants.select ||
    ((StateName1.SelectedValue != null) && (StateName1.SelectedValue.ToString() == StringConstants.select)))



请在此处查看有关异常做法的说明:
我如何制作滚动条到达底部时将停止的循环 [当我运行应用程序时,异常是捕获了如何处理? [



Please see my directions on exception practices here:
How do i make a loop that will stop when a scrollbar reaches the bottom[^],
When i run an application an exception is caught how to handle this?[^].

—SA


这篇关于异常处理错误的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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