Bug? "code too large for try statement" in a Sub with no Try statement

Alessandro71

Well-Known Member
Licensed User
Longtime User
I have a cross platform (B4A/B4i) app which compiles fine on B4A, but the B4i compiler stops with the following message:

Rich (BB code):
B4i line: 1179
End Sub
shell\src\com\powercruisecontrol\check\b4i_carmodel_subs_0.java:165: error: code too large for try statement
catch (Exception e) {
^
1 error

The referenced line is the "End Sub" of a Sub with no try/catch statements at all.
Looking at the java code, it looks like a try/catch is automatically inserted by the compiler.
Is there a workaround for this?
 

Sandman

Expert
Licensed User
Longtime User
Just curious, how many lines are in the try statement in the java code? And how many lines in B4i for that same section?
 

Alessandro71

Well-Known Member
Licensed User
Longtime User
B4i code: 550 lines
resulting java code: 162 lines

the code is actually a sub with a big CreateMap

note: while counting lines for answering your question, I noticed that the error occurs only in Debug mode.
Release mode is fine.
 

stevel05

Expert
Licensed User
Longtime User
Without seeing the code I'm guessing in the dark but can't you split the code. Use CreateMap for the elements that aren't going to fail and add the ones that might in a try block afterwards?
 

DonManfred

Expert
Licensed User
Longtime User
there is no try block at all
there are try catch-blocks added if you compile the b4x-code to an app which results in java-files.

if you got this error one solution (probably the best) is to split up the sub into several smaller SUBs.
 
Last edited:

Alessandro71

Well-Known Member
Licensed User
Longtime User
This error can happen with very large subs, in debug mode. It hits a limit of the Java compiler. As @DonManfred wrote, the solution is to split the large sub.

It sometimes happen when the developer puts the data inside the code. Something that isn't recommended.
this case is peculiar: the sub is not "large" (550 lines), but consisting of a CreateMap of objects.
i don't see how this kind of data can be put outside of the code.
B4X:
dataset = CreateMap( _
    CAR1:    Array As Object(m_1, m_2), _
    CAR1:    Array As Object(m_1, m_3, m_4), _
...

anyway, as i said, i solved by splitting the sub
 
Last edited:

emexes

Expert
Licensed User
There is a 64k limit on modules, of either code or literal data or both (can't remember).

550 lines would average to 120 bytes per array of objects, and between the array descriptor and the objects and maybe associated garbage-keeping information, it wouldn't surprise me if an array of three objects was around that same size.
 

emexes

Expert
Licensed User
"64k limit on modules" and it's 1981 all over again :)

The limit was discussed in a 2019 thread:


and it took me a while to find the more-detailed info on it because that page no longer exists:

https://www.javaworld.com/article/2073208/reproducing--code-too-large--problem-in-java.html

and there is another discussion of it at:

 
Top