这种结构对方法有用吗? [英] Is this structure good for methods?

查看:72
本文介绍了这种结构对方法有用吗?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

寻找关于这种方法结构的一些意见,即

方式错误的处理和报告:

http://pastebin.com/711366


我认为这是一个很好的方法诱捕并移动

数据流。


有人建议更好的方法吗?


史蒂文


***通过开发人员指南 http://www.developersdex发送。 com ***

Looking for some opinions on the structure of this method, namely the
way errors are handled and reported:

http://pastebin.com/711366

My view is this is quite a good method of trapping and moving through a
flow of data.

Anyone suggest a better way?

Steven

*** Sent via Developersdex http://www.developersdex.com ***

推荐答案

Steven Blair< st ********** @ btinternet.com>写道:
Steven Blair <st**********@btinternet.com> wrote:
寻找关于这种方法结构的一些意见,即处理和报告错误的方式:

http://pastebin.com/711366

我认为这是相当的诱捕和移动数据流的好方法。

有人建议更好的方法吗?
Looking for some opinions on the structure of this method, namely the
way errors are handled and reported:

http://pastebin.com/711366

My view is this is quite a good method of trapping and moving through a
flow of data.

Anyone suggest a better way?




我强烈建议你查找异常,异常处理,并查看

它们是如何工作的。


- Barry



I strongly suggest you look up exceptions, exception handling, and see
how they work.

-- Barry


我知道异常。

它们经常在我的应用程序中使用(需要时)

但是这个鳕鱼的例子,在我看来并不适合包裹
尝试,捕获块。

示例中的所有方法都不会抛出异常。


***通过Developersdex发送 http://www.developersdex.com ***
I know about exceptions.
They are used frequently in my applications (when required)
But this cod example, in my opinion is not suitable for wrapping around
try, catch blocks.
None of the methods in the example will throw an exception.

*** Sent via Developersdex http://www.developersdex.com ***


Steven Blair< st ********** @ btinternet.com> ;写道:
Steven Blair <st**********@btinternet.com> wrote:
我知道异常。
它们经常在我的应用程序中使用(需要时)
但是这个鳕鱼的例子,在我看来并不适合环绕着
尝试,捕获块。
示例中的所有方法都不会抛出异常。
I know about exceptions.
They are used frequently in my applications (when required)
But this cod example, in my opinion is not suitable for wrapping around
try, catch blocks.
None of the methods in the example will throw an exception.




你不知道 - 更重要的是,你不应该知道,通过

封装原则。有人在一年之后修改代码可能会抛出异常,或者可能以其他方式破坏这个不变量。


我个人会编写你的代码像这样:


--- 8< ---

公共覆盖字符串ProcessMessage()

{

试试

{

ParseMessage();

GetProductDetails();

返回无论如何输出" ;;

}

catch(例外情况)

{

LogException(ex);

返回无论输出多少;

}

}

---> 8 ---


其中ParseMessage()和GetProductDetails()抛出异常如果

是一个错误 - 我甚至不想捕获异常,

并让调用堆栈中的另一个方法进一步捕获

异常。


- Barry



You don''t know that - more importantly, you shouldn''t know that, by
principle of encapsulation. Somebody modifying the code a year later may
throw an exception, or may in some other way break this invariant.

I, personally, would write your code like this:

---8<---
public override string ProcessMessage()
{
try
{
ParseMessage();
GetProductDetails();
return "whatever output";
}
catch (Exception ex)
{
LogException(ex);
return "whatever output";
}
}
--->8---

Where ParseMessage() and GetProductDetails() throw exceptions if there
is an error - and I would even prefer not catching the exception at all,
and letting another method further up the call stack catch the
exception.

-- Barry

这篇关于这种结构对方法有用吗?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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