运行时异常不终止程序 [英] Runtime exception not terminating the programm
问题描述
根据我的一点点Java知识程序,它应该在它抛出运行时异常后终止。
As per my little-bit java knowledge Program supposed to be terminated after it throws runtime exception.
但是在我的应用程序抛出运行时异常之后它没有终止,当我在linux上执行它时,我必须使用 ctrl + c 来终止它,否则它就不会终止。
But in my application after throwing runtime exception it is not terminating ,and as i am executing it on linux i have to use ctrl+c to terminate it, Otherwise it just do not terminate.
我是在windows系统上创建jar并将其复制粘贴到linux中。
I am creating jar on windows sytem and copy paste it in linux.
此外,我在我的应用程序中启用了日志记录。
Also i have logging enabled in my application.
更新:
我没有捕获任何异常
没有使用多线程。
Update: I am not catching any exception No multithreading is used.
推荐答案
A RuntimeException
(或任何 例外
或 Throwable
)不必然会终止您的应用程序。
A RuntimeException
(or any Exception
or Throwable
) does not necessarily terminate your application.
仅 终止您的应用程序如果它仅在 非守护程序线程上抛出而且未被处理。
It only terminates your applications if it's thrown on the only non-daemon thread and is not handled.
这意味着如果另一个没有n-daemon线程正在运行或你捕获异常,应用程序将不终止。
That means that if either another non-daemon thread is running or you catch the exception, the application will not be terminated.
我最近的回答给出了总结发生了什么(特别是关于 OutOfMemoryError
,但想法是一样的。)
This recent answer from me gives a summary of what happens (it's specifically about an OutOfMemoryError
, but the idea is the same).
这篇关于运行时异常不终止程序的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!