开发者

Try/catch in JSP fails

A try/catch statement in my Java code (embedded in JSP) fails with the following error:

An error occurred at line: 26 in the jsp file: /template/tampabay/includes/omniture-footer.jsp
Syntax error on token "}", delete this token

I am unable to determine why the following code produces that error:

<%!
    /*
     * Map the DTI categories to the appropriate SiteCatalyst category
     * structure.
     */
    ArrayList<HashMap> mapDTIToSiteCatalystCategories( ArrayList<HashMap> dti_categories ) {
        ArrayList<HashMap> site_catalyst_categories = new ArrayList<HashMap>();
        ArrayList<Integer> dti_category_ids = new ArrayList<Integer>();
        for ( int i = 0; i < 4; i++ ) {
            try {
                dti_categor开发者_如何学运维y_ids.add( Integer.parseInt( (String)dti_categories.get( i ).get( "id" ) ) );
            }
            catch ( NumberFormatException e ) {
                dti_category_ids.add( -1 );
            }
        }
        // - Snip -
    }

The error corresponds to the twelfth line above ( the closing brace of the try statement ). However, the code looks syntactically correct to me. Aside from breach of protocol by embedding a scriptlet in JSP, can you help point out the error?

I have tried using variations of this code (removing the for loop and declaring separate variables) but the error persists whenever I try to use the try/catch statement.

EDIT:

I uploaded the complete code listing here.

EDIT 2: I also receive the following error:

An error occurred at line: 44 in the jsp file: /template/tampabay/includes/omniture-footer.jsp
Syntax error, insert "}" to complete Block

This error corresponds to the fourth line below:

              "", "Baseball",
              "", ""
        );
    break;
case 120: // Baseball: Minors
    site_catalyst_categories = addElements(
        dti_category_ids.get( 0 ), "Sports",

I did not include it before because I assumed it was caused by the earlier error. However, in light of the comments, it may be relevant.

According to my IDE and my visual inspection, all of the braces are properly paired. However, the compiler disagrees.


It looks like, on line 131/132, there's a missing close curly for the try statement.

                    case 131:
                        try {
                            switch ( dti_category_ids.get( 2 ) ) {
                               case 252: // Colleges: Bulls ..snip..
                               case 253: // Colleges: Bulls ..snip..
                               case 254: // Colleges: Bulls ..snip..
                               default: // Log all others to the "College" section
                            }
                            break;
                        // HERE ... THERE'S NO } TO CLOSE THE try {
                        catch ( NumberFormatException e ) {
                            // Log all others to the "College" section
                            site_catalyst_categories = addElements(
                                    dti_category_ids.get( 0 ), "Sports",
                                    "", "College",
                                    "", "",
                                    "", ""
                                );

                        }
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜