我正在处理一些我并不熟悉的ASP代码。我需要将下面的代码(原始代码)转换/更改为Java(我没有专家)
我理解了一些语法,但我有点卡在代码行开始" On Error Resume Next"我不知道Java使用哪个函数。
这部分让我失望 (不确定"下一步"需要使用Java)
任何帮助将不胜感激
<% <!-- each string had DIM in front ex. DIM fEmptyRecordset So i believe I changed what was needed --->
<%
Boolean fEmptyRecordset = ""; ' as Boolean
Boolean fFirstPass = ""; ' as Boolean
Boolean fNeedRecordset = ""; ' as Boolean
Command cmdTemp = ""; ' as Command
Double dblUnits = ""; ' as Double
Double dblRateFrom = ""; ' as Double
Double dblRateTo = ""; ' as Double
Double newRate = ""; ' as Double
Double newUnits = ""; ' as Double
String NewCurrName = ""; ' as String
String NewCurrName2 = ""; ' as String
' Convert currency
fEmptyRecordset = true;
fFirstPass = true;
fNeedRecordset = true;
<!--- here is where I'm stuck, I don't quite understand the "On Error Resume Next" function that ASP uses. I'm just looking for gudance in which function this is related to in Java --->
On Error Resume Next
if (fNeedRecordset) {
Set con_currency_sdo = Server.CreateObject("ADODB.Connection")
con_currency_sdo.ConnectionTimeout = con_currency_sdo_ConnectionTimeout
con_currency_sdo.CommandTimeout = con_currency_sdo_CommandTimeout
con_currency_sdo.Open con_currency_sdo_ConnectionString, con_currency_sdo_RuntimeUserName, con_currency_sdo_RuntimePassword
Set cmdTemp = Server.CreateObject("ADODB.Command")
Set GetRate = Server.CreateObject("ADODB.Recordset")
' Find out what the common base currency is and get the corresponding rates for both
' the From and To currencies. Order desc to get USD, GBP, EUR. (USD is preferred)
cmdTemp.CommandText = "SELECT FROMCURR.BASE_CURR_CODE, " & _
"FROMCURR.CURR_RATE_BASE_FC FROMRATE, TOCURR.CURR_RATE_BASE_FC TORATE, " & _
"CURRNAMEFROM.BLMBG_CURR_NAME FROMCURRNAME, CURRNAMETO.BLMBG_CURR_NAME TOCURRNAME " & _
"FROM AON_CURR_DAILY_EXCH_RATE_SDO FROMCURR, AON_CURR_DAILY_EXCH_RATE_SDO TOCURR, " & _
"AON_CURRENCY_SDO CURRNAMEFROM, AON_CURRENCY_SDO CURRNAMETO " & _
"WHERE FROMCURR.CURR_CODE='" & Request.Form("selBaseCurr") & _
"' AND TOCURR.CURR_CODE='" & Request.Form("selTargetCurr") & _
"' AND FROMCURR.BASE_CURR_CODE=TOCURR.BASE_CURR_CODE" & _
" AND FROMCURR.CURR_CODE=CURRNAMEFROM.CURR_CODE" & _
" AND TOCURR.CURR_CODE=CURRNAMETO.CURR_CODE" & _
" AND FROMCURR.CURR_DATE='" & dateString & _
"' AND TOCURR.CURR_DATE='" & dateString & _
"' ORDER BY FROMCURR.BASE_CURR_CODE DESC;"
cmdTemp.CommandType = 1
Set cmdTemp.ActiveConnection = con_currency_sdo
GetRate.Open cmdTemp, , 0, 1
' Place all error codes in comments
if (Err.number <> 0) {
fEmptyRecordSet = true;
out.println("<!-- ADO Errors Begin -->" & "\r\n")
for (Object objError : con_currency_sdo.Errors) {
out.println("<!-- ADO Error.Number = " & objError.Number & "-->" & "\r\n")
out.println("<!-- ADO Error.Description = " & objError.Description & "-->" & "\r\n")
out.println("<!-- ADO Error.Source = " & objError.Source & "-->" & "\r\n")
out.println("<!-- ADO Error.SQLState = " & objError.SQLState & "-->" & "\r\n")
out.println("<!-- ADO Error.NativeError = " & objError.NativeError & "-->" & "\r\n")
Next <!--- Not sure what "Next" needs to be in Java --->
out.println("<!-- ADO Errors End -->" & "\r\n")
out.println("<!-- VBScript Errors Begin -->" & "\r\n")
out.println("<!-- Err.number = " & Err.number & "-->" & "\r\n")
out.println("<!-- Err.description = " & Err.description & "-->" & "\r\n")
out.println("<!-- Err.source = " & Err.source & "-->" & "\r\n")
out.println("<!-- VBScript Errors End -->" & "\r\n")
if (checkDate = true) {
%>
答案 0 :(得分:3)
这个问题的答案真的归结为:
如果答案是#1,恭喜。它就像try {} catch(e)
之间的所有代码一样简单On Error Resume Next
和
if (Err.number <> 0) {
Err.number和Err.Description是错误代码/描述。您可以改为使用Exception组件。
如果答案是#2,那么你只想尝试{}捕获(e)可以异常的代码,并根据失败的原因正确地处理每个异常。每种方法都有不同的例外情况。看起来唯一的方法是实际的ADO Open()
调用,因此这是我在try {} catch()中包含的唯一方法。
无论哪种方式,您都不会记录所有这些ADO属性。我会记录任何异常/异常文本/ stacktrace作为异常对象的一部分吐出。
答案 1 :(得分:1)
它是处理异常的vb脚本方式,告诉程序在发生错误时继续执行到下一行。