In java, “5/0” statement doesn't fire SIGFPE signal on my Linux machine, why?

后端 未结 6 1688
庸人自扰
庸人自扰 2021-01-18 17:04

I wrote a very simple c program:

#include

int main(){
    int a=2;
    int b=0;
    printf(\"%d\\n\", a/b);
}

and run it wi

6条回答
  •  无人共我
    2021-01-18 17:46

    Here, it raises a SIGFPE.

    You forgot to tell strace to follow children. Add the -f option to strace and you should see something similar to:

    [pid  2304] read(3, "\312\376\272\276\0\0\0001\0n\n\0\23\0I\t\0\3\0J\7\0K\n\0L\0M\n\0N\0"..., 2369) = 2369
    [pid  2304] --- SIGFPE (Floating point exception) @ 0 (0) ---
    [pid  2304] rt_sigreturn(0x1c50800)     = 5
    [pid  2304] write(2, "Exception in thread \"main\" ", 27Exception in thread "main" ) = 27
    [pid  2304] write(2, "java.lang.ArithmeticException: /"..., 40java.lang.ArithmeticException: / by zero) = 40
    [pid  2304] write(2, "\n", 1
    

提交回复
热议问题