Java : OutOfMemoryError with Examples
OutOfMemoryError (Java SE 21 & JDK 21) with Examples.
You will find code examples on most OutOfMemoryError methods.
Summary
try {
final var array = new int[1000000000];
} catch (OutOfMemoryError e) {
System.out.println(e);
}
// Result
// ↓
//java.lang.OutOfMemoryError: Java heap space
Constructors
OutOfMemoryError ()
final var e = new OutOfMemoryError();
System.out.println(e); // java.lang.OutOfMemoryError
OutOfMemoryError (String s)
final var e = new OutOfMemoryError("abcd");
System.out.println(e); // java.lang.OutOfMemoryError: abcd
System.out.println(e.getMessage()); // abcd
Methods declared in Throwable
addSuppressed, fillInStackTrace, getCause, getLocalizedMessage, getMessage, getStackTrace, getSuppressed, initCause, printStackTrace, printStackTrace, printStackTrace, setStackTrace, toString
Please see the link below.
Related posts
- API Examples
- Error
- Exception
- RuntimeException
- ArithmeticException
- ArrayIndexOutOfBoundsException
- ArrayStoreException
- CancellationException
- ClassCastException
- ConcurrentModificationException
- DateTimeException
- DateTimeParseException
- IllegalArgumentException
- IllegalStateException
- IndexOutOfBoundsException
- NoSuchElementException
- NullPointerException
- PatternSyntaxException
- StringIndexOutOfBoundsException
- UnsupportedOperationException
- Throwable