有什么例外可以捕获 [英] What Exceptions to catch

查看:128
本文介绍了有什么例外可以捕获的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述




我需要在File.Delete上捕捉异常情况()


查看帮助后,我注意到了thgere是serevral

例外情况可以抛出。

我的问题是,我应该抓住所有的例外情况,还是我只是做了以下几个b $ b :


试试

{


}


catch(例外e)

{

e.Message; //用这个做一些有用的东西

}


这会捕获File.Delete可以抛出的所有异常吗?


问候,


史蒂文

***通过Developersdex发送 http://www.developersdex.com ***

不要只是参加USENET ......获得奖励!

解决方案




如果你正在做insinde,那么try {} catch就是File.Delete ,执行一个

catch(例外e),这将捕获可能引发的所有事件。

System.Exception是所有例外的母亲和意志因此可以获得所有

可能的例外情况。


Erik


" Steven Blair" < ST ********** @ btinternet.com>在消息中写道

新闻:Oq ************** @ tk2msftngp13.phx.gbl ...


我需要在File.Delete()上查看异常情况

在查看帮助后,我注意到thgere是serevral
可以抛出异常。
我的问题是,我应该抓住所有的例外,还是我只是做以下事情:

尝试
{

}

catch(例外e)
{
}

这会捕获File.Delete可以抛出的所有异常吗?

问候,

史蒂文

***通过开发人员指南发送 http://www.developersdex .com ***
不要只是参加USENET ......获得奖励!





http://msdn.microsoft.com/library/de...eleteTopic.asp


这里列出了所有例外情况提高。当然,有了Exception,你可以抓住它们,但是如果你需要根据

异常类型进行特定的处理,那么选择多个catch子句是一种选择。 br />

-

Teemu Keiski

MCP,Microsoft MVP(ASP.NET),AspInsiders会员

ASP.NET论坛版主,AspAlliance专栏作家
http://blogs.aspadvice.com / joteke


" Steven Blair" < ST ********** @ btinternet.com>在消息中写道

新闻:Oq ************** @ tk2msftngp13.phx.gbl ...


我需要在File.Delete()上查看异常情况

在查看帮助后,我注意到thgere是serevral
可以抛出异常。
我的问题是,我应该抓住所有的例外,还是我只是做以下事情:

尝试
{

}

catch(例外e)
{
}

这会捕获File.Delete可以抛出的所有异常吗?

问候,

史蒂文

***通过开发人员指南发送 http://www.developersdex .com ***
不要只是参加USENET ......获得奖励!



嗨史蒂文,

这会捕获File.Delete可以抛出的所有异常吗?




它会这样做,如果全部你需要知道的是,删除

文件是否有问题,如果你需要做不同的事情取决于

为什么它会让你失望?应该捕获特定的异常,在这种情况下你可以

声明例如两个捕获一个你感兴趣的异常

in和其他异常捕获所有其他的。

干杯,


-

Ignacio Machin,
ignacio.machin AT dot.state.fl.us

佛罗里达州交通局


Hi,

I need to catch exceotions on File.Delete()

After checking the help, I have noticed that thgere are serevral
Exceptions that can be thrown.
My question is, should I catch all thes Exceptions, or if I simply do
the following:

try
{

}

catch(Exception e)
{
e.Message; //do something useful with this
}

Will this catch all the Exceptions that a File.Delete can throw ?

Regards,

Steven
*** Sent via Developersdex http://www.developersdex.com ***
Don''t just participate in USENET...get rewarded for it!

解决方案

Hi,

If all you''re doing insinde try {} catch is File.Delete, do a
"catch(exception e)", this will capture all events that could be raised.
System.Exception is the mother of all exceptions and will thus catch all
possible exceptions.

Erik

"Steven Blair" <st**********@btinternet.com> wrote in message
news:Oq**************@tk2msftngp13.phx.gbl...

Hi,

I need to catch exceotions on File.Delete()

After checking the help, I have noticed that thgere are serevral
Exceptions that can be thrown.
My question is, should I catch all thes Exceptions, or if I simply do
the following:

try
{

}

catch(Exception e)
{
e.Message; //do something useful with this
}

Will this catch all the Exceptions that a File.Delete can throw ?

Regards,

Steven
*** Sent via Developersdex http://www.developersdex.com ***
Don''t just participate in USENET...get rewarded for it!



Hi,

http://msdn.microsoft.com/library/de...eleteTopic.asp

here are listed all the exceptions it can raise. Sure, with Exception you
can catch them all, but if you need to do specific processing based on
exception type, having more than one catch clause is an option.

--
Teemu Keiski
MCP, Microsoft MVP (ASP.NET), AspInsiders member
ASP.NET Forum Moderator, AspAlliance Columnist
http://blogs.aspadvice.com/joteke

"Steven Blair" <st**********@btinternet.com> wrote in message
news:Oq**************@tk2msftngp13.phx.gbl...

Hi,

I need to catch exceotions on File.Delete()

After checking the help, I have noticed that thgere are serevral
Exceptions that can be thrown.
My question is, should I catch all thes Exceptions, or if I simply do
the following:

try
{

}

catch(Exception e)
{
e.Message; //do something useful with this
}

Will this catch all the Exceptions that a File.Delete can throw ?

Regards,

Steven
*** Sent via Developersdex http://www.developersdex.com ***
Don''t just participate in USENET...get rewarded for it!



Hi steven,

Will this catch all the Exceptions that a File.Delete can throw ?



It will do that, if all you need to know is if was a problem deleting the
file that''s the way to go, if you need to do different things depending of
why it fails you should catch the particular exception, in this case you can
declare for example two catch one for the exception that you are interested
in and other for Exception to catch all the others.
Cheers,

--
Ignacio Machin,
ignacio.machin AT dot.state.fl.us
Florida Department Of Transportation


这篇关于有什么例外可以捕获的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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