System.exit() return 可以不终止 JVM 吗?
Can System.exit() return without terminating the JVM?
在实践中当然不太可能发生,但是:
此方法调用不终止 JVM 是否有任何原因?
是否有可能,例如,在调用 System.exit(0)
之后(或同时)立即抛出 OutOfMemoryError
或调用此方法时发生 WhosebugError
,因为堆栈是就在那一刻溢出?
Is there any reason for this method call not to terminate the JVM?
是的。
Throws:
SecurityException - if a security manager exists and its checkExit method doesn't allow exit with the specified status.
我无法在 System.exit()
上产生堆栈溢出
public static void main(String[] args)
{
try
{
main(args); // recursion
}
catch (WhosebugError e1)
{
System.out.println("OK.");
}
try
{
System.exit(0);
}
catch (WhosebugError e2)
{
System.out.println("HA!");
}
}
发生e1
后,println()
和exit()
仍然有效,好像堆栈上还有一些space。
在实践中当然不太可能发生,但是: 此方法调用不终止 JVM 是否有任何原因?
是否有可能,例如,在调用 System.exit(0)
之后(或同时)立即抛出 OutOfMemoryError
或调用此方法时发生 WhosebugError
,因为堆栈是就在那一刻溢出?
Is there any reason for this method call not to terminate the JVM?
是的。
Throws:
SecurityException - if a security manager exists and its checkExit method doesn't allow exit with the specified status.
我无法在 System.exit()
public static void main(String[] args)
{
try
{
main(args); // recursion
}
catch (WhosebugError e1)
{
System.out.println("OK.");
}
try
{
System.exit(0);
}
catch (WhosebugError e2)
{
System.out.println("HA!");
}
}
发生e1
后,println()
和exit()
仍然有效,好像堆栈上还有一些space。