gpt4 book ai didi

c# - 'throw' 或 'try...catch' 会影响性能吗?

转载 作者:行者123 更新时间:2023-11-30 18:54:15 25 4
gpt4 key购买 nike

<分区>

Possible Duplicate:
How slow are .NET exceptions?

我一直在到处(包括这里)阅读有关何时应该/不应该使用异常的信息。我现在想更改我的代码,使该方法返回 false 并像那样处理它,但我的问题是:是 throwing 还是 try..catch-ing 会阻碍性能......?我的意思是,这是否可以接受:


bool method someMmethod()
{
try
{
// ...Do something
catch (Exception ex) // Don't care too much what at the moment...
{
// Output error
// Return false
}
return true // No errors

或者有更好的方法吗?(我讨厌看到“未处理的异常......”大声笑!)

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com