来自库或数据层的异常的最佳返回类型 [英] Best return type for an exception from a library or data layer
问题描述
我将所有数据操作都放在一个单独的库中,所以我正在寻找可能被称为最佳实践的
。关于这些类的返回类型。
例如,假设我将UI层中的更新发送到
库类中的方法,该类调用存储过程。最好返回一个布尔值
表示成功/失败,返回带有异常消息的字符串,或者
只返回整个异常?
I have all of my data operations in a separate library, so I''m looking for
what might be termed "best practices" on a return type from those classes.
For example, let''s say I send an update from the UI layer to a method in a
library class that calls the stored procedure. Best to return a boolean
indicating success/failure, return a string with the exception message, or
just return the entire exception?
推荐答案
2006年12月3日星期日14:25:20 -0500,Earl写道:
On Sun, 3 Dec 2006 14:25:20 -0500, Earl wrote:
我拥有所有的数据操作在一个单独的库中,所以我在寻找
可能被称为最佳实践的东西。关于这些类的返回类型。
例如,假设我将UI层中的更新发送到
库类中的方法,该类调用存储过程。最好返回一个布尔值
表示成功/失败,返回带有异常消息的字符串,或者
只返回整个异常?
I have all of my data operations in a separate library, so I''m looking for
what might be termed "best practices" on a return type from those classes.
For example, let''s say I send an update from the UI layer to a method in a
library class that calls the stored procedure. Best to return a boolean
indicating success/failure, return a string with the exception message, or
just return the entire exception?
嘿伯爵,
就个人而言,我会在异常中返回一个例外情况
留言
-
Bits.Bytes
http://bytes.thinkersroom.com
" Rad [Visual C#MVP]" < no **** @ nospam.comwrote in message
news:t2 ************************** *@40tude.net ...
"Rad [Visual C# MVP]" <no****@nospam.comwrote in message
news:t2***************************@40tude.net...
On Sun,2006年12月3日14:25:20 -0500,Earl写道:
On Sun, 3 Dec 2006 14:25:20 -0500, Earl wrote:
>我将所有数据操作都放在一个单独的库中,所以我正在寻找
可能被称为最佳实践的内容。从那些
类返回类型。
例如,假设我从UI层发送更新到
库类的方法调用存储过程。最好返回一个布尔值
表示成功/失败,返回带有异常消息的字符串,
或
只返回整个异常?
>I have all of my data operations in a separate library, so I''m looking
for
what might be termed "best practices" on a return type from those
classes.
For example, let''s say I send an update from the UI layer to a method in
a
library class that calls the stored procedure. Best to return a boolean
indicating success/failure, return a string with the exception message,
or
just return the entire exception?
嘿伯爵,
就个人而言,我会在异常中返回一个例外情况
留言
Hey Earl,
Personally i''d return an exception with the details in the exception
message
否!你没有返回例外,成功标志,消息或任何其他表示成功或失败的b $ b。函数应返回数据,如果
合适,或返回void。如果失败则应该是例外情况
抛出。
David
No! You don''t "return" an exception, a success flag, a message or anything
else to indicate success or failure. Functions should return data, if
appropriate, or return void. If there is a failure an exception should be
"thrown".
David
>
On Sun,2006年12月3日14:46:09 -0600,David Browne写道:
On Sun, 3 Dec 2006 14:46:09 -0600, David Browne wrote:
" Rad [Visual C#MVP]" < no **** @ nospam.comwrote in message
news:t2 ************************** *@40tude.net ...
"Rad [Visual C# MVP]" <no****@nospam.comwrote in message
news:t2***************************@40tude.net...
> On Sun,2006年12月3日14:25:20 -0500,Earl写道:
>On Sun, 3 Dec 2006 14:25:20 -0500, Earl wrote:
>>我将所有数据操作都放在一个单独的库中,所以我正在寻找
可能被称为最佳实践的内容。从那些
类返回类型。
例如,假设我从UI层发送更新到
库类的方法调用存储过程。最好返回一个布尔值
表示成功/失败,返回带有异常消息的字符串,
或
只返回整个异常?
>>I have all of my data operations in a separate library, so I''m looking
for
what might be termed "best practices" on a return type from those
classes.
For example, let''s say I send an update from the UI layer to a method in
a
library class that calls the stored procedure. Best to return a boolean
indicating success/failure, return a string with the exception message,
or
just return the entire exception?
嘿伯爵,
我个人会在异常中返回一个例外情况
消息
Hey Earl,
Personally i''d return an exception with the details in the exception
message
不!你没有返回例外,成功标志,消息或任何其他表示成功或失败的b $ b。函数应返回数据,如果
合适,或返回void。如果失败则应该是例外情况
抛出。
David
No! You don''t "return" an exception, a success flag, a message or anything
else to indicate success or failure. Functions should return data, if
appropriate, or return void. If there is a failure an exception should be
"thrown".
David
语义学的朋友,语义学。你完全清楚我的意思!
-
Bits.Bytes
http://bytes.thinkersroom.com
这篇关于来自库或数据层的异常的最佳返回类型的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!