首页 > Java,手动throw exception和error有什么区别?

Java,手动throw exception和error有什么区别?

示例代码如下

                if (input.length != 2) {
                    logger.error("The input for execute " + component.toString() + " is not right!");
                    throw new Exception("hehehe");
                }

                if (input.length != 2) {
                    logger.error("The input for execute " + component.toString() + " is not right!");
                    throw new Error("hehehe");
                }

我记得好像说是你的程序里永远用不到throw error


Exception:

1.可以是可被控制(checked) 或不可控制的(unchecked)。
2.表示一个由程序员导致的错误。
3.应该在应用程序级被处理。

Error:

1.总是不可控制的(unchecked)。
2.经常用来用于表示系统错误底层资源的错误。
3.如何可能的话,应该在系统级被捕捉。

【热门文章】
【热门文章】