哪些操作可能(不会)引发StackOverflowError? [英] What operations may (not) throw StackOverflowError?

查看:116
本文介绍了哪些操作可能(不会)引发StackOverflowError?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

StackOverError 被扔?

或者,什么时候会抛出?

Or rather, when will it not be thrown?

对于示例,如果我们使用基本运算符++=--=== <>/%,等等:

For example, if we use the primitive operators +, +=, -, -=, == <, >, /, %, etc:

try {
     // operations +, +=, -, -=, == <, >, /, %, etc
} catch (java.lang.StackOverflowError e) {
     // will never occur?
}

是否可以保证不会抛出StackOverflowError?

Is there any guarantee that StackOverflowError will not be thrown?

推荐答案

是真的,不调用任何函数的代码永远不会抛出java.lang.StackOverflowError?

A StackOverflowError is-a VirtualMachineError.事实证明,VirtualMachineError s没有 no 无扔保证. Java虚拟机规范说明了以下内容(强调).

A StackOverflowError is-a VirtualMachineError. It transpires that there are no no-throw guarantees about VirtualMachineErrors. The Java Virtual Machine Specification says the following (emphasis added).

此规范无法预测内部错误或资源限制可能在哪里 会被遇到,并不能准确地报告它们.因此, 下面定义的任何VirtualMachineError子类都可能在处抛出 在Java虚拟机运行期间的任何时间: ... StackOverflowError

This specification cannot predict where internal errors or resource limitations may be encountered and does not mandate precisely when they can be reported. Thus, any of the VirtualMachineError subclasses defined below may be thrown at any time during the operation of the Java virtual machine: ... StackOverflowError

这篇关于哪些操作可能(不会)引发StackOverflowError?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆