Catching java.lang.OutOfMemoryError?

前端 未结 14 1479
Happy的楠姐
Happy的楠姐 2020-11-22 06:01

Documentation for java.lang.Error says:

An Error is a subclass of Throwable that indicates serious problems that a reasonable application

14条回答
  •  难免孤独
    2020-11-22 06:48

    For the question 2 I already see the solution I would suggest, by BalusC.

    1. Is there any real word scenarios when catching java.lang.OutOfMemoryError may be a good idea?

    I think I just came across a good example. When awt application is dispatching messages the uncatched OutOfMemoryError is displayed on stderr and the processing of the current message is stopped. But the application keeps running! User may still issue other commands unaware of the serious problems happening behind the scene. Especially when he cannot or does not observe the standard error. So catching oom exception and providing (or at least suggesting) application restart is something desired.

提交回复
热议问题