如果发生错误,那么它将变为子 DisplayCustomError 但它不会引发异常。预期结果 - 在 objHTTP.send (json) 之后它应该抛出异常消息。我试过 Call Err.Raise 但它没有抛出任何东西。代码在VBscript中
sub run
On Error Resume Next
wrapper.getVariable( "Plant_Price_PerKW" ).value = excel.range( "'Cases'!$H$331" )
wrapper.getVariable( "Net_Present_Value" ).value = excel.range( "'Cases'!$H$782" )
wrapper.getVariable( "IRR" ).value = excel.range( "'Cases'!$H$783" )
Dim strMessage
If Err.Number <> 0 And excel.range( "'Cases'!$H$783" ) = "" Then
strMessage = "IRR cannot be computed. "
DisplayCustomError(strMessage)
WScript.Quit
ElseIf Err.Number <> 0 And (excel.range( "'Cases'!$H$783" ) <> "") Then
strMessage = "Other Outputs cannot be computed."
DisplayCustomError(strMessage)
WScript.Quit
End If
end sub
Sub DisplayCustomError(strMessage)
If Err.Number <> 0 Then
Dim errorMessage, objHTTP, URL, json, errorCode, uniqueId, networkInfo, jobId
errorMessage ="Error while executing EVMLite. Error number " & Err.Number & ". " & Err.Description & " " & Err.Source & strMessage
errorCode = "ERR-1004"
uniqueId = wrapper.getVariable("UniqueId").value
Set networkInfo = CreateObject("WScript.NetWork")
jobId = networkInfo.ComputerName
Set objHTTP = CreateObject("MSXML2.ServerXMLHTTP")
URL = "http://10.93.244.224343:9005/vpp/logerror"
objHTTP.Open "POST", URL, False
objHTTP.SetRequestHeader "Content-Type", "application/json"
json = "{""jobId"": """& jobId &""", ""uniqueId"": """& uniqueId &""", ""errorCode"": """& errorCode &""", ""errorMessage"": """& errorMessage &"""}"
'MsgBox json
objHTTP.send (json)
On Error Goto 0
Call Err.Raise(vbObjectError + 10, "EVM Failed to execute", errorMessage)
'MsgBox objHTTP.ResponseText
End If
end sub