-2

I'm working with some ASP code which I'm not really to familiar with. I need to convert/change the code below (original code) to Java (Which I'm no expert in)

I understand some of the syntax but I'm kind of stuck at the line of code beginning "On Error Resume Next" I don't know which function to use that Java uses.

This part is throwing me off ( Not sure what "Next" needs to be in Java )

any help would be appreciated

<%  <!-- 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) {
%>
Lynn Crumbling
  • 12,985
  • 8
  • 57
  • 95
POPEYE1716
  • 79
  • 11
  • 3
    This question appears to be off-topic because StackOverflow is not a code-conversion service - no specific question has been asked. – user2864740 Sep 17 '14 at 04:18
  • Converting the code amounts to *rewriting* the code while maintaining equivalent semantics. This requires are least basic knowledge of *both* systems. (And JavaScript is *not* Java.) – user2864740 Sep 17 '14 at 04:19
  • 1
    @pep Then he/she can look it up. If that is the only question then it should be asked in a more clear and straightforward manner, including a better focused title and without a bunch of irrelevant code. "This requires are least basic knowledge of both systems." – user2864740 Sep 17 '14 at 06:18

2 Answers2

3

The answer to this question really comes down to:

  • (1) Do you want to replicate this EXACTLY.. or...
  • (2) Do you want to Do-The-Right-Thing (tm)

If the answer is #1, congrats. It's as simple as try{} catch(e) all of the code between

On Error Resume Next

and

if (Err.number <> 0) {

Err.number and Err.Description were the error code/description. You can just use the Exception components instead.

If the answer is #2, then you'll want to only try {} catch(e) the code that can exception out, and act on each exception correctly and according to what the failure was. Each method has different exceptions that it can throw. Looks like the only method is the actual ADO Open() call, so that's the only one I'd wrap in a try{} catch().

Either way, you aren't going to have all of these ADO Properties to log. I'd log whatever exception/exception text/stacktrace gets spit out as part of the exception object.

Lynn Crumbling
  • 12,985
  • 8
  • 57
  • 95
1

It's the vb script way to handle exceptions, tells the program to continue execution to next line when an error occurs.

Answered here What does the "On Error Resume Next" statement do?

Community
  • 1
  • 1
Steve V.
  • 56
  • 2