Monday, 25 June 2012
Java error message 'code too large for try statement'
I thought we can put any number of lines in between try and catch. After all its a programming language and it can execute whatever we give. However, until recently I got an error which scold me by saying 'code too large for try statement'. Basically the problem is our fellow programmers using JSP includes and parent JSP has try block which includes several JSPs (using include file directive) and catch block which has some exception handling stuff. I modified one of the included JSP and added few lines of code. This caused the above error. After little study I found that Java language has a limitation on the size of a method. That limit is 65535 (number of bytes the code occupies). This behavior may be different from compiler to compiler or server to server. I didn't dig it to that extent to find out the behaviors of containers. But one day I will do! The solution is to refactor and modularize the code. Also try to use jsp dynamic includes rather than static includes.