Catching such kinds of dimension errors at runtime is possible. You need to use the flags:
- for gfortran:
-fcheck=all(includes-fcheck=bounds) - for ifort/ifx:
-check all(includes-check bounds)
In the particular case of ifx v2024.0 use -check all,nouninit to bypass a compiler bug.