.NET有一个破坏的异常模型 [英] .NET has a broken Exception model
问题描述
public DateTime Value
{
get
{
try
{
返回新的DateTime(int.Parse(tbYear.Text),int.Parse(tbMonth.Text),
int.Parse(tbDay.Text)); < br $>
}
catch(FormatException)
{
//在这里做点什么
}
catch(ArgumentException)
{
//在这里做东西
}
catch(溢出异常)
{
//在这里做东西
}
}
因为没有好基类(不,我不会遇到System.Exception)我需要分别捕获所有三个例外。如果所有三个例外
需要相同的错误处理我必须编写三次代码或
必须为这个愚蠢的小异常创建一个单独的方法
处理。
为什么不是所有非致命SystemExceptions的单个基类?
还有很多其他的例子,例如一个简单的调用Process.Start,它可以使用
抛出4个不同的例外,我必须处理它们。
(InvalidOperation,Argument,Win32,ObjectDisposed)。
请MS,修改你的异常模型!
如果MS无法解决这个问题,请至少允许使用类似
$ b的语法$ b catch(ArgumentException,OverflowException,FormatExcepti on)
{
}
-
cody
免费工具,游戏和幽默
http://www.deutronium.de.vu || http://www.deutronium.tk
Cody:
如果我理解正确,那么功能已经存在。你可以从ApplicationException继承
,当非致命的应用程序发生时会抛出这个错误:
http://msdn.microsoft.com/library/de。 ..us / cpref / html /
frlrfSystemApplicationExceptionClassTopic.asp
HTH,
Bill
www.devbuzz.com
www.knowdotnet.com
" cody" <无**************** @ gmx.net>在消息中写道
news:#i ************** @ TK2MSFTNGP12.phx.gbl ...public DateTime Value
{
获得
{
尝试
返回新的DateTime(int.Parse(tbYear.Text),
int.Parse(tbMonth) .Text),int.Parse(tbDay.Text));
}
catch(FormatException)
{
//在这里做点什么
}
catch(ArgumentException)
{
//在这里做东西
}
catch(溢出异常)
{
//在这里做点什么
}
}
由于没有好的基类(不,我不会捕获System.Exception)我必须分别捕获所有三个例外。如果所有三个异常
需要相同的错误处理我必须编写三次代码或
必须创建一个单独的方法只为这个愚蠢的小异常处理。
为什么没有一个基类用于所有非致命的SystemExceptions?
还有很多其他的例子,例如一个简单的调用Process.Start,
可以抛出4个不同的异常,我必须处理
(InvalidOperation,Argument,Win32,ObjectDisposed)。
请MS,修改你的异常模型!
如果MS无法处理这个问题,请至少允许使用类似
catch的语法(ArgumentException,OverflowException,FormatExcepti on)
{
-
免费软件工具,游戏和幽默
http://www.deutronium.de.vu || http://www.deutronium.tk
>
>如果我理解正确,功能已经存在。你可以从ApplicationException继承,当非致命的
应用程序错误发生时抛出:
http://msdn.microsoft.com/ library / de ... us / cpref / html / frlrfSystemApplicationExceptionClassTopic.asp
你一定是在开玩笑,我怎样才能影响
$抛出的异常b $ b int.Parse或Process.Start?
前段时间我有一个线程解决了同样的问题:
http://www.dotnet247.com/247referenc...47/236575.aspx
-
cody
[免费软件,游戏和幽默]
< a rel =nofollowhref =http://www.deutronium.de.vutarget =_ blank> www.deutronium.de.vu || www.deutronium.tk
Cody:
我很抱歉,我以为你指的是应用程序异常,但是
看到代码我看到了你的观点。
"科迪" < PL ********** @ gmx.de>写在消息
新闻:好的************* @ TK2MSFTNGP10.phx.gbl ...如果我理解正确,那么功能已经存在。你
可以从ApplicationException继承,当非致命的
应用程序错误发生时抛出:
http://msdn.microsoft.com/library/de...us/cpref/html/frlrfSystemApplicationExceptionClassTopic.asp
你一定是在开玩笑,我怎样才能影响
int.Parse或Process.Start抛出哪些异常?
>我前段时间有一个线程解决了同样的问题:
http://www.dotnet247.com/247referenc...47/236575.aspx
-
cody
[免费软件,游戏和幽默]
www.deutronium.de.vu || www.deutronium.tk
public DateTime Value
{
get
{
try
{
return new DateTime(int.Parse(tbYear.Text), int.Parse(tbMonth.Text),
int.Parse(tbDay.Text));
}
catch (FormatException)
{
// do stuff here
}
catch (ArgumentException)
{
// do stuff here
}
catch (OverflowException)
{
// do stuff here
}
}
Since there is no good base class (No, I won''t catch System.Exception) I
have to catch all three exceptions separately. If all three exceptions
requires the same error handling I have to write the code three times or
have to create a separate method only for this stupid small exception
handling.
Why not one single base-class for all non-fatal SystemExceptions?
There are many other examples, e.g. a simple call to Process.Start which can
throw 4 different exceptions which I have to deal with
(InvalidOperation,Argument,Win32,ObjectDisposed).
Please MS, revise your exception model!
If MS cannot handle this, please allow at least a syntax like
catch (ArgumentException,OverflowException,FormatExcepti on)
{
}
--
cody
Freeware Tools, Games and Humour
http://www.deutronium.de.vu || http://www.deutronium.tk
Cody:
If I understand you correctly, the functionality is already there. You can
inherit from ApplicationException which is thrown when non-fatal application
errors happen:
http://msdn.microsoft.com/library/de...us/cpref/html/
frlrfSystemApplicationExceptionClassTopic.asp
HTH,
Bill
www.devbuzz.com
www.knowdotnet.com
"cody" <no****************@gmx.net> wrote in message
news:#i**************@TK2MSFTNGP12.phx.gbl...public DateTime Value
{
get
{
try
{
return new DateTime(int.Parse(tbYear.Text), int.Parse(tbMonth.Text), int.Parse(tbDay.Text));
}
catch (FormatException)
{
// do stuff here
}
catch (ArgumentException)
{
// do stuff here
}
catch (OverflowException)
{
// do stuff here
}
}
Since there is no good base class (No, I won''t catch System.Exception) I
have to catch all three exceptions separately. If all three exceptions
requires the same error handling I have to write the code three times or
have to create a separate method only for this stupid small exception
handling.
Why not one single base-class for all non-fatal SystemExceptions?
There are many other examples, e.g. a simple call to Process.Start which can throw 4 different exceptions which I have to deal with
(InvalidOperation,Argument,Win32,ObjectDisposed).
Please MS, revise your exception model!
If MS cannot handle this, please allow at least a syntax like
catch (ArgumentException,OverflowException,FormatExcepti on)
{
}
--
cody
Freeware Tools, Games and Humour
http://www.deutronium.de.vu || http://www.deutronium.tk
> If I understand you correctly, the functionality is already there. You
caninherit from ApplicationException which is thrown when non-fatal application errors happen:
http://msdn.microsoft.com/library/de...us/cpref/html/ frlrfSystemApplicationExceptionClassTopic.asp
You must be joking, how can I influence which Exceptions are thrown by
int.Parse or Process.Start?
I had a thread some time ago which addressed the same problem:
http://www.dotnet247.com/247referenc...47/236575.aspx
--
cody
[Freeware, Games and Humor]
www.deutronium.de.vu || www.deutronium.tk
Cody:
My apologies, I thought you were referring to application exceptionss but
seeing the code I see your point.
"cody" <pl*************************@gmx.de> wrote in message
news:Ok*************@TK2MSFTNGP10.phx.gbl...If I understand you correctly, the functionality is already there. You
caninherit from ApplicationException which is thrown when non-fatal
applicationerrors happen:
http://msdn.microsoft.com/library/de...us/cpref/html/frlrfSystemApplicationExceptionClassTopic.asp
You must be joking, how can I influence which Exceptions are thrown by
int.Parse or Process.Start?
I had a thread some time ago which addressed the same problem:
http://www.dotnet247.com/247referenc...47/236575.aspx
--
cody
[Freeware, Games and Humor]
www.deutronium.de.vu || www.deutronium.tk
这篇关于.NET有一个破坏的异常模型的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!