如何尝试抓住C# [英] How to do try and catch in c#

查看:103
本文介绍了如何尝试抓住C#的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

问题1)follwong代码是否正确,因为我是第一次学习try catch

question 1) is the follwong code is correct because first time i''m learning try catch

try
    {
    string x = (string)GetGlobalResourceObject(Resource1, value);

    Label1.Text = string.Format("{0}", x);
    }

catch (Exeption ex)
{
    Response.Write(ex.ToString());
}



问题2)当我运行它时,出现类似
的错误



question 2) when i run it i get the error like

Error	1	The type or namespace name ''Exeption'' could not be found (are you missing a using directive or an assembly reference?)	C:\Documents and Settings\cmsdev3\My Documents\Visual Studio 2005\Projects\CreatingCheckBoxList\CreatingCheckBoxList\new.aspx.cs	44	28	CreatingCheckBoxList







and

Error	2	The name ''ex'' does not exist in the current context	C:\Documents and Settings\cmsdev3\My Documents\Visual Studio 2005\Projects\CreatingCheckBoxList\CreatingCheckBoxList\new.aspx.cs	46	40	CreatingCheckBoxList



[edit]整理了代码块,并添加了一个选项,将我的内容作为纯文本..."选项已禁用,缩进-OriginalGriff [/edit]



[edit]Code blocks tidied, and one added, "Treat my content as plain text..." option disabled, indentation - OriginalGriff[/edit]

推荐答案

是因为Exception 拼写为"c" ...
That is because Exception is spelled with a ''c''...


首先是throw,然后是trycatch!开个玩笑:)
语法看起来正确.但是,您需要使用
First throw and then try to catch it! Just kidding :)
The syntax looks correct. However, you need to use
catch(System.Exception ex)

或使用

using System;

在文件开头输入span class ="code-keyword">.可以在错误语句本身中看到此提示.
找不到类型或名称空间名称"Exeption"(您是否缺少using指令或程序集引用?)
希望这会有所帮助.

还应注意,Exception拼写错误.

in the beginning of your file. This hint can be seen in the error statement itself.
The type or namespace name ''Exeption'' could not be found (are you missing a using directive or an assembly reference?)
Hope this helps.

Also noted that Exception is misspelled.


这篇关于如何尝试抓住C#的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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