How does the JRE know the line number of the code where the exception occurred?

Consider the following exception print

java.util.NoSuchElementException at java.util.StringTokenizer.nextToken(StringTokenizer.java:332) at com.infoaxe.mr.homefeed.ReduceTwo.reduce(MapReduce.java:290) 

Since Java is a compiled language, and what works in the JVM is bytecode and not the source code itself, how is the exception known, on which line did it happen? Example line 332 in the above example?

+4
source share
1 answer

Just because the compiler includes line numbers in the generated bytecode. There are -g options (in the Oracle javac compiler), which allows you to disable this if you want.

+15
source

All Articles