Home > java > Code too large for try statement ?

Code too large for try statement ?

If you didn’t already know it, the java language specification has limits on the size of a method. That limit is 65535 (number of bytes that the code occupies).

This so called limitation has never really bothered me. After practicing object oriented programming, modularization and good design principles you can only ask yourself ‘Who is crazy enough to write a method whose size is greater than 65535 !?’. But you know what ? It can happen. There are so many code gen tools out there and common libraries that will write code for you. Rules engines, JSP compilers, scripting/template engines will write dynamic code for you. If they do not write it withing the 65535 bytes limit, your code will not compile or will give a cryptic error and die.

Code suffering from this phenomenon will see this message – “Code too large to compile” or “Code too large for try statement“. So umm.. where did the try statement come from ?

Jave Server Page (JSP) templates sometimes follow a syntax that resembles this

# Include Header
# Content
catch(Exception e)
//Handle it
# footer

If you end up writing complex logic in your JSP and include (static includes) other files to partake in the final output, you might end up breaking your page. The error is not necessarily well defined. The same JSP page which might compile with version 8 of weblogic will fail  in version 10 or might compile in tomcat and fail in JBOSS. This is because each container writes code within the JSP in its own way.

The try catch may not even be introduced by you. Your container may introduce the try catch (for whatever internal reasons) for code written in the JSP. This problem is famous for creeping up when you move from one container to another or shift between container versions. The error occurs either when you request for a JSP page the first time (and the container tries to compile it) or when you try to pre compile the JSP for performance reasons.


Help your container modularize the code. Try splitting the JSP into several chunks and make dynamic includes instead of static ones. Dynamic includes (jsp:include against %@include) will compile the JSP and then stream the output instead of trying to include all the code into one big method or try catch block.

You can read up on the limitation here


Look for this text

The value of the code_length item must be less than 65536

Categories: java Tags: , ,
  1. August 20th, 2009 at 13:24 | #1

    Normally, with well designed code (front and backend) this wouldn’t happen, but as you say, code generation or other container initiated activity might cause this. Good to point it out though; it is one of those things that will almost never happen, but when it does it would be really hard to find the cause.

  2. August 21st, 2009 at 11:06 | #2

    article is presented nicely.
    problem and solution… good :)

  3. Srikanth
    August 22nd, 2009 at 17:37 | #3

    yes, it’s interesting to know that limit in methods ……..

  4. Indu
    December 9th, 2010 at 07:42 | #4

    Good article. Presented well.

  5. February 6th, 2011 at 10:39 | #5

    A good article!

    Thanks :)

  6. Ville
    September 29th, 2011 at 08:09 | #6

    Thanks! Dynamic includes was my solution in my JSP-code :)

  7. Rajendra Verma
    December 9th, 2011 at 15:03 | #7

    very nice Article

  8. Max
    May 17th, 2012 at 17:00 | #8

    Nice and simple explanation. Its good that you pointed out that each container handles compilation in its own way so something that works fine in one container may blow up in another. One has to look into this on a case by case basis, there is no “one way” to get rid of this problem.

  9. July 20th, 2014 at 01:00 | #9

    TRM Filtration is the leading the world for giving air filtration and
    environment hazard solutions for more than four
    decades. For more than forty years, we have been able to increase global ease as well
    as proficiency by top-notch items and solutions. TRM has increased ease and efficiency across the world by its modern products as well as most reliable assistance for almost four decades.
    TRM filtering devices are existing nearly in each section of our daily life and these are discovered around the
    world. TRM Filtration has achieved worldwide recognition for consultation, helping with design, specialized service and sales service especially in business oriented purposes.
    Undoubtedly, we will promote well being as well as well being
    by giving healthy and clean air by our globally recognized products.

    To be the original equipment manufacturer, the TRM Filtration company gives the filtration products of
    TRM by itself. Such filtration systems are available in adjustable configurations for
    plenty of reasons. All of the TRM filters have maximum quality and small air to
    cloth proportion. They’re ecologically clean as well as eliminating
    about 99.9 percent of waste particles.

  10. February 10th, 2015 at 05:05 | #10

    VPNs can be installed on smart phones (i – Phone, Android, Nokia, Blackberry, etc) and
    computers (Mac, Windows, Linux), and VPN routers can be used to change
    the IP of your Apple TV, Roku, or Blu Ray device.
    My mother adored her new son-in-law as he was married
    to her daughter who, all my life, could never do
    anything wrong. In Nashua, Susan was diagnosed bi-polar and told
    to always keep to a schedule of taking her prescribed medicines or
    face the possibility of more traumatic incidents.
    At no time did BANK OF AMERICA take any steps to disclose the Hustle
    to Fannie Mae or Freddie Mac. Life is full of surprises and not all are pleasant.

  11. Zen
    February 26th, 2015 at 06:51 | #11

    Mine too.

  12. May 2nd, 2015 at 07:13 | #12

    Appreciate it for this post, I am a big fan of this website would like to continue updated.

  13. June 2nd, 2015 at 10:27 | #13

    This is my first time pay a quick visit at here and i am
    actually pleassant to read all at alone place.

  14. June 22nd, 2015 at 07:29 | #14

    Very interesting subject, thank you for posting.

  15. October 18th, 2015 at 10:25 | #15

    Utterly written content, regards for selective information. “No human thing is of serious importance.” by Plato.

  16. sanjay
    October 20th, 2015 at 01:03 | #16


  17. October 27th, 2015 at 13:51 | #17

    Hi there, I wish for to subscribe for this website to get latest updates,
    thus where can i do it please help.

  18. November 10th, 2015 at 10:57 | #18

    certainly like your web site but you need to test the spelling on quite a few of your posts. A number of them are rife with spelling problems and I in finding it very troublesome to inform the reality on the other hand I’ll definitely come again again.

  19. November 23rd, 2015 at 09:15 | #19

    You can certainly see your expertise in the paintings you write. The arena hopes for even more passionate writers like you who are not afraid to mention how they believe. Always follow your heart. “We are near waking when we dream we are dreaming.” by Friedrich von Hardenberg Novalis.

  1. No trackbacks yet.