1

I have an OOM error(Perm Gen is full), problem is when I am logging the error message into the log file, error occurs while the classloader is loading the exception handling class.

Prashant_M
  • 2,868
  • 1
  • 31
  • 24
4ier
  • 11
  • 2

2 Answers2

0

You shouldn't handle errors as your application is in abnormal state:

https://docs.oracle.com/javase/7/docs/api/java/lang/Error.html

Differences between Exception and Error

This answer explains scenario where you might want to do it though:

Catching java.lang.OutOfMemoryError?

Community
  • 1
  • 1
Rahul
  • 637
  • 5
  • 16
  • I've never had any problem recovering from an `OutOfMemoryError` in particular. Some allocation failed, the try block got disrupted and the program happily continues on. ... The program *would* be in an inconsistent state if the body of the try block is designed badly, that is, if some user-imposed invariants are corrupted if interrupted half-way. – Mark Jeronimus Jan 31 '18 at 09:39
0

You can either throw this error to handle where you're using it or you can put a try catch block around your logic(code) and you can log the error inside the catch or finally block.

Rahul
  • 863
  • 6
  • 23
  • I think you need to read the Java Doc, OutOfMemoryError is not an exception!!! https://docs.oracle.com/javase/7/docs/api/java/lang/OutOfMemoryError.html – Rahul Jan 31 '18 at 08:52