I needed a page to throw an exception for an experiment and added
#{1/0}
to index.xhtml
. I expected an java.lang.ArithmeticException
to be thrown, however the expression evaluated to the string Infinity
on the generated page. Division by zero is not defined and NaN
is probably a much better choice than Infinity
, but even NaN
is confusing because it's not intuitive in the Java programming language where division by zero is handled with an exception instead of this return value.
Running
@PostConstruct
public void init() {
int x = 1/0;
}
in a backing bean causes the expected java.lang.ArithmeticException: / by zero
.
Besides an explanation why this happens, I'd be interested in a way to throw the exception because I prefer early and severe crashs of the application during development over displaying of logical (or unlogical for that reason) string.
I checked the large list of potential duplicates (x/0 == NaN
in other languages, etc.) carefully, but there seems to be no explanation for JSF, yet. I'm not looking for a solution of any kind (there's no problem, I just found this behavior by accident), but an explanation.
I experienced this using Primefaces 6.2.