我有一个关于如何正确处理错误的问题。我正在开发一个三层应用程序。如果在数据层上创建错误,我想将错误传递到业务层并在那里进行处理。实现这一目标的最佳方法是什么?我正在使用 .net 2.0 和 Visual Studio 2005。
感谢您的建议 杰森
最佳答案
在业务层中使用 Try...Catch
并在 Try 中调用数据层。
Try
'call data-layer
Catch ex As Exception
'deal with exception / log
End Try
如果您仍然想在数据层中使用Try...Catch
,那么您需要Throw
(以保留堆栈跟踪)或Throw ex
在 Catch 中,否则根本不要在数据层中使用 Try...Catch
。
Try
data = dataLayer.GetData()
Catch ex As Exception
Throw
End Try
关于asp.net - VB.net 向父级抛出错误,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/9465035/