C#异常未经检查??? [英] C# Exception is Unchecked???

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

问题描述

我正在使用Visual Studio 2K3编写ASP.NET Web应用程序。是否有一种强制C#编译器捕获可能的异常的方法?


在Java中,必须捕获所有抛出的异常,否则编译器会给出

你错了。在C#中,有没有办法做到这一点?

I am using Visual Studio 2K3 writing a ASP.NET web application. Is there a
way to force the C# compiler to catch possible exception?

In Java, all exceptions thrown MUST BE caught, otherwise compiler would give
you error. In C#, is there a way to do that?

推荐答案

现在你知道为什么我不使用Java了。 />

不,C#不会强迫你抓住你的错误。这取决于你做什么,并且

这是有道理的。你并不总是希望在本地捕获每一个错误。虽然

这是一个很好的做法,但它不应该是一个绝对的要求。


---尼克


ChInKPoInt [No MCSD]" <章******************* @ gmail.com>在消息中写道

新闻:G5 ******************** @ rogers.com ...
now you know why I don''t use Java.

No, C# will not FORCE you to catch your errors. That''s up to you to do, and
it makes sense. You don''t always want to catch every error locally. While
it is good practice, it should not be an absolute requirement.

--- Nick

"ChInKPoInt [No MCSD]" <Ch*******************@gmail.com> wrote in message
news:G5********************@rogers.com...
我我正在使用Visual Studio 2K3编写ASP.NET Web应用程序。是否有
强制C#编译器捕获可能的异常的方法?

在Java中,必须捕获所有抛出的异常,否则编译器将
给出错误。在C#中,有没有办法做到这一点?
I am using Visual Studio 2K3 writing a ASP.NET web application. Is there a way to force the C# compiler to catch possible exception?

In Java, all exceptions thrown MUST BE caught, otherwise compiler would give you error. In C#, is there a way to do that?



Nick Malik< ni ******* @ hotmail.nospam .COM>写道:
Nick Malik <ni*******@hotmail.nospam.com> wrote:
现在你知道我为什么不使用Java了。

不,C#不会强迫你抓住你的错误。这取决于你做什么,而且这是有道理的。你并不总是希望在本地捕获每一个错误。虽然这是一个很好的做法,但它不应该是一个绝对的要求。
now you know why I don''t use Java.

No, C# will not FORCE you to catch your errors. That''s up to you to do, and
it makes sense. You don''t always want to catch every error locally. While
it is good practice, it should not be an absolute requirement.




它不是Java。你不必在本地捕获每一个例外(甚至

检查异常) - 你只需要声明你可以抛出哪个检查

例外。


我相信检查某种异常是个好主意;我不是

确保Java做对了,而C#/ .NET并没有把它完全取消它们。 Java因为它们而感觉有点麻烦,

和C#有时感觉就像没有安全带的驾驶一样,因为它们缺少了b $ b。第一个获得异常处理的语言/平台

真的是正确的会很有趣......


-

Jon Skeet - < sk *** @ pobox.com>
http://www.pobox.com/~skeet

如果回复小组,请不要给我发邮件



It''s not in Java. You don''t have to catch every exception (or even
checked exception) locally - you just have to declare which checked
exceptions you can throw.

I believe that checked exceptions of some kind are a good idea; I''m not
sure that Java got it right, and C#/.NET didn''t get it right by getting
rid of them entirely. Java feels slightly cumbersome because of them,
and C# sometimes feels like driving without a seatbelt due to the lack
of them. The first language/platform which gets exception handling
really "right" will be interesting...

--
Jon Skeet - <sk***@pobox.com>
http://www.pobox.com/~skeet
If replying to the group, please do not mail me too


Nope C#不支持检查异常。下面是Bruce Eckle和Anders Hejlsberg的成绩单,讨论他们为什么不在C#中。

http://www.artima.com/intv/handcuffs.html


问候


Richard Blewett - DevelopMentor
http://www.dotnetconsult.co.uk / weblog
http://www.dotnetconsult.co.uk


我正在使用Visual Studio 2K3编写ASP.NET Web应用程序。是否有一种强制C#编译器捕获可能的异常的方法?


在Java中,必须捕获所有抛出的异常,否则编译器会给出

你错了。在C#中,有没有办法做到这一点?
Nope C# doesn''t support checked exceptions. Heres a transcript of Bruce Eckle and Anders Hejlsberg discussing why they are not in C#.

http://www.artima.com/intv/handcuffs.html

Regards

Richard Blewett - DevelopMentor
http://www.dotnetconsult.co.uk/weblog
http://www.dotnetconsult.co.uk

I am using Visual Studio 2K3 writing a ASP.NET web application. Is there a
way to force the C# compiler to catch possible exception?

In Java, all exceptions thrown MUST BE caught, otherwise compiler would give
you error. In C#, is there a way to do that?


这篇关于C#异常未经检查???的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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