小编qkp*_*kpk的帖子

java try-catch-finally递归问题

public class Foo {

    public static void main(String[] args) {
        foo();
    }

    public static void foo() {
        try {
            System.out.println("try");
            foo();
        } catch (Throwable e) {
            System.out.println("catch");
            foo();
        } finally {
                System.out.println("finally");
                foo();
        }
    }
}
Run Code Online (Sandbox Code Playgroud)

谁能解释一下这段代码的输出?

1.在eclipse(无尽)客户端模式下输出:


    try
    try
    ....


    ...
    ...
    tryfinallyfinally
    tryfinallyfinally
    try
    try
    try
    tryfinallyfinally
    tryfinallyfinally
    try
    tryfinallyfinally
    tryfinallyfinally
    try
    ....
    ....

2.output on linux(crash)服务器模式:


    try
    try
    ...

    ...
    try
    try
    try
    try
    try
    try
    MISSING EXCEPTION HANDLER for pc 0x00002aaaab1c53f0 and handler bci -1
       Exception: …

java recursion finally try-catch

4
推荐指数
1
解决办法
2812
查看次数

标签 统计

finally ×1

java ×1

recursion ×1

try-catch ×1