在WCF-Service中使用下面的try-catch语句
Try
'Here some method is being called.
Return myBs.PerformDailyUpdate()
Catch ex As Exception 'Exception is not being caught here
If service IsNot Nothing AndAlso service.HasWarnings Then
TextFileTracer.Write(String.Format("Warning in method: '{0}'.", name))
TextFileTracer.Write(service.GetWarnings)
End If
Try
TextFileTracer.Write("Error in dbmanager: " & service.HasErrors.ToString)
Catch ex2 As Exception
End Try
TextFileTracer.Write(String.Format("Error in method: '{0}'.", name))
TextFileTracer.Write(ex.Message & vbCrLf & ex.StackTrace)
End Try
End Function 'Exception shows here while debugging在该方法(PerformDailyUpdate)中,调用一个ASMX-Webservice (.Net 2.0)。这个webservice偶尔抛出一个SOAPException,它是由从那个webservice.yet调用的方法引起的,不知怎么的,这个SOAPException正在被上面的方法捕获。
我的问题:,为什么SOAPException没有被抓?是否有一些特征将SOAP-异常与正常生成的“异常”分离开来(这反过来又导致它没有被捕获)?
注意事项:这里编写的代码不是我的。所以请不要在这件事上评判我
ExceptionMessage (第一部分)
System.Web.Services.Protocols.SoapException: Unexpected application error: SqlException.
ADF.ExceptionHandling.GlobalExceptions.UnexpectedException: Unexpected application error: SqlException.
System.Data.SqlClient.SqlException: Incorrect syntax near ')'.
at System.Data.SqlClient.SqlConnection.OnError(SqlException exception, Boolean breakConnection)
at System.Data.SqlClient.SqlInternalConnection.OnError(SqlException exception, Boolean breakConnection)
....谢谢
Scheme (how this clarifies the situation somewhat):
Internal DailyTriggerMechanism -----> WCF - Service -----> ASMX-Webservice ----> DB2/SQL
(Origin code above) (Exception being thrown)在WCF中,数据接收被操纵以填充特定的表。在这种情况下,可能不会改变。
发布于 2014-01-30 13:35:38
我认为一个正常的异常应该能够捕获所列出的未处理的错误,但是除了常规的异常之外,您还可以尝试一个特定于SOAP的和/或与SQL相关的异常。
比如:
try {
//your failing code
}
catch (SOAPException se)
{
//your response }
catch (SQLException sqle)
{
//your response
}
catch (Exception e)
{
//your response
}https://stackoverflow.com/questions/21456844
复制相似问题