【发布时间】:2013-01-22 05:20:34
【问题描述】:
我的程序抛出了一个我应该处理的错误。但我无法返回字符串消息,因为它是一个返回数据集的函数:
Public Function getUserInfo(ByValue testUserIdAs String) As DataSet
Dim dsUseInfo As DataSet = New DataSet()
Try
Dim objTestWs As New TestWebService.UserMaintenanceSoapClient
dsUseInfo = objTestWs.dsGetUserInfo(TestOU, PAC, paramUserID)
Return (dsUseInfo)
Catch ex As Exception
' TEST FIX ERROR HANDLING -LIWM Please search how to return custom error. I want to return "userid already exists"
Throw
End Try
我正在考虑加入:
If error
then return "Error Message"
但我不能将它作为类型字符串返回。
【问题讨论】:
-
您在 catch 块中抛出异常,因此您不会返回数据集。只需在抛出异常时包含您想要的错误消息,例如
throw new Exception("User not found");。不是最优雅的解决方案,但它会让你得到你想要的。
标签: vb.net exception types exception-handling dataset