deeplearning4j/deeplearning4j · critical · IllegalArgumentException

integer range badly formed

Error message

integer range badly formed: {rng}

What it means

The catch-all branch of the backward-cpp terminate handler in libnd4j. When std::terminate fires with something that is NOT derived from std::exception (e.g. `throw 42;`, a thrown pointer, or a rethrown foreign exception), the handler cannot print a type or message and falls back to 'Unknown exception type'. It signals that native code threw a non-standard object and the process is about to abort after a stack trace.

Solutions

  1. Use the printed stack trace to locate the throw site; convert all throws in custom code to std::runtime_error subclasses.
  2. Audit for cross-ABI exception passing and rebuild all native modules with a consistent compiler and -fexceptions settings.
  3. Run with catchthrow (gdb: `catch throw`) to capture the original throw before it becomes terminate.
  4. Check for exceptions crossing CUDA host/device or JNI boundaries and translate them at each boundary.

Example fix

// before
throw -1;
// after
throw std::runtime_error("kernel launch failed");
Defensive patterns

Strategy: try-catch

Try / catch

try { nativeCall(); } catch (...) { convertToJavaException("unknown native error"); }

Prevention

When it happens

Trigger: A `throw` of a non-std::exception value, or a foreign exception (e.g. propagating through JNI from code built with different exception ABI) reaches std::terminate and is handled by `catch (...)`.

Common situations: Mixed-ABI native builds (different compilers/flags) where exceptions cross shared-library boundaries incorrectly; legacy code throwing ints or char*; CUDA kernel callbacks throwing non-exception values.

Related errors


AI-assisted analysis of deeplearning4j/deeplearning4j@4c22ac5fe4 (2026-09-07). Data as JSON: /api/errors/467efcd6d2d254f0. Report an issue: GitHub.

Appendix: source

Thrown at datavec/datavec-api/src/main/java/org/datavec/api/conf/Configuration.java:629

     * above means 2, 3, 5, and 7, 8, 9, ...
     */
    public static class IntegerRanges {
        private static class Range {
            int start;
            int end;
        }

        List<Range> ranges = new ArrayList<Range>();

        public IntegerRanges() {}

        public IntegerRanges(String newValue) {
            StringTokenizer itr = new StringTokenizer(newValue, ",");
            while (itr.hasMoreTokens()) {
                String rng = itr.nextToken().trim();
                String[] parts = rng.split("-", 3);
                if (parts.length < 1 || parts.length > 2) {
                    throw new IllegalArgumentException("integer range badly formed: " + rng);
                }
                Range r = new Range();
                r.start = convertToInt(parts[0], 0);
                if (parts.length == 2) {
                    r.end = convertToInt(parts[1], Integer.MAX_VALUE);
                } else {
                    r.end = r.start;
                }
                if (r.start > r.end) {
                    throw new IllegalArgumentException("IntegerRange from " + r.start + " to " + r.end + " is invalid");
                }
                ranges.add(r);
            }
        }

        /**
         * Convert a string to an int treating empty strings as the default value.
         * @param value the string value

View on GitHub (pinned to 4c22ac5fe4)