# Segmentation fault when a try to catch a InterruptException

**URL:** https://discourse.julialang.org/t/segmentation-fault-when-a-try-to-catch-a-interruptexception/2285
**Category:** General Usage
**Tags:** interruptexception
**Created:** [February 24, 2017, 8:02pm UTC](https://discourse.julialang.org/t/segmentation-fault-when-a-try-to-catch-a-interruptexception/2285 "2017-02-24T20:02:11Z")
**Posts on this page:** 10
**Page:** 1

<div class="post-metadata">

### Author: ![Alvaro\_M](https://avatars.discourse-cdn.com/v4/letter/a/b487fb/32.png) [@Alvaro\_M](https://discourse.julialang.org/u/Alvaro_M)
#### Post date: [February 24, 2017, 8:02pm UTC](https://discourse.julialang.org/t/segmentation-fault-when-a-try-to-catch-a-interruptexception/2285/1 "2017-02-24T20:02:11Z")

</div>

Hi,

I have this code, I’m trying to catch a keyboard interrupt, but what a get it a segmentation fault

```julia
try
  for i in 1:10
    println(i)
    sleep(0.5)
  end
catch err
   if isa(err, InterruptException)
     exit() 
   end
   rethrow
end

```

**Version 0.5.1-pre+55 (2017-02-13 09:11 UTC)**  
_Commit 8d4ef37 (11 days old release-0.5)_\*  
**x86\_64-linux-gnu**

Regards.

Álvaro.

---

<div class="post-metadata">

### Author: ![kristoffer.carlsson](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/kristoffer.carlsson/32/22_2.png) [@kristoffer.carlsson](https://discourse.julialang.org/u/kristoffer.carlsson)
#### Post date: [February 24, 2017, 8:06pm UTC](https://discourse.julialang.org/t/segmentation-fault-when-a-try-to-catch-a-interruptexception/2285/2 "2017-02-24T20:06:50Z")

</div>

As a note, it seems to work fine on the master branch.

---

<div class="post-metadata">

### Author: ![yuyichao](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/yuyichao/32/20_2.png) [@yuyichao](https://discourse.julialang.org/u/yuyichao)
#### Post date: [February 24, 2017, 8:08pm UTC](https://discourse.julialang.org/t/segmentation-fault-when-a-try-to-catch-a-interruptexception/2285/3 "2017-02-24T20:08:21Z")

</div>

Also the `rethrow` line won’t actually throw anything and are you sure it’s actually an segfault?

---

<div class="post-metadata">

### Author: ![Alvaro\_M](https://avatars.discourse-cdn.com/v4/letter/a/b487fb/32.png) [@Alvaro\_M](https://discourse.julialang.org/u/Alvaro_M)
#### Post date: [February 24, 2017, 8:15pm UTC](https://discourse.julialang.org/t/segmentation-fault-when-a-try-to-catch-a-interruptexception/2285/4 "2017-02-24T20:15:11Z")

</div>

Yes it is a segfault, signal 11.

I’m recompiling everything

```julia
make cleanall
make

```

And still getting a segfault:

```julia
unknown function (ip: 0x40176d)
unknown function (ip: 0x401256)
__libc_start_main at /lib/x86_64-linux-gnu/libc.so.6 (unknown line)
unknown function (ip: 0x40129a)
unknown function (ip: 0xffffffffffffffff)
Allocations: 966693 (Pool: 965785; Big: 908); GC: 0

signal (11): Violación de segmento

```

---

<div class="post-metadata">

### Author: ![Alvaro\_M](https://avatars.discourse-cdn.com/v4/letter/a/b487fb/32.png) [@Alvaro\_M](https://discourse.julialang.org/u/Alvaro_M)
#### Post date: [February 24, 2017, 9:21pm UTC](https://discourse.julialang.org/t/segmentation-fault-when-a-try-to-catch-a-interruptexception/2285/5 "2017-02-24T21:21:42Z")

</div>

Hi again,

I delete all and install from master, and still get:

```julia
signal (2): Interrupción
while loading /home/x/test.jl, in expression starting on line 1
syscall at /lib/x86_64-linux-gnu/libc.so.6 (unknown line)
4
uv__epoll_wait at /home/x/src/julia/deps/srccache/libuv-52d72a52cc7ccd570929990f010ed16e2ec604c8/src/unix/linux-syscalls.c:321
uv__io_poll at /home/x/src/julia/deps/srccache/libuv-52d72a52cc7ccd570929990f010ed16e2ec604c8/src/unix/linux-core.c:267
uv_run at /home/x/src/julia/deps/srccache/libuv-52d72a52cc7ccd570929990f010ed16e2ec604c8/src/unix/core.c:354
process_events at ./libuv.jl:83
wait at ./event.jl:171
wait at ./event.jl:27
wait at ./event.jl:344
sleep at ./event.jl:385
macro expansion at /home/x/test.jl:4 [inlined]
anonymous at ./<missing> (unknown line)
jl_call_method_internal at /home/x/src/julia/src/julia_internal.h:248 [inlined]
jl_toplevel_eval_flex at /home/x/src/julia/src/toplevel.c:589
jl_parse_eval_all at /home/x/src/julia/src/ast.c:874
jl_load at /home/x/src/julia/src/toplevel.c:616
include_from_node1 at ./loading.jl:539
unknown function (ip: 0x7f72cc9b9e6b)
jl_call_method_internal at /home/x/src/julia/src/julia_internal.h:248 [inlined]
jl_apply_generic at /home/x/src/julia/src/gf.c:2212
include at ./sysimg.jl:14
unknown function (ip: 0x7f72cc87332b)
jl_call_method_internal at /home/x/src/julia/src/julia_internal.h:248 [inlined]
jl_apply_generic at /home/x/src/julia/src/gf.c:2212
process_options at ./client.jl:305
_start at ./client.jl:371
unknown function (ip: 0x7f72cc9e6478)
jl_call_method_internal at /home/x/src/julia/src/julia_internal.h:248 [inlined]
jl_apply_generic at /home/x/src/julia/src/gf.c:2212
unknown function (ip: 0x401cb1)
unknown function (ip: 0x401502)
__libc_start_main at /lib/x86_64-linux-gnu/libc.so.6 (unknown line)
unknown function (ip: 0x4015a9)
unknown function (ip: 0xffffffffffffffff)
Allocations: 1091447 (Pool: 1090170; Big: 1277); GC: 0

```

Am I doing something wrong or it’s time to open a issue?

Thanks.

Álvaro.

---

<div class="post-metadata">

### Author: ![yuyichao](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/yuyichao/32/20_2.png) [@yuyichao](https://discourse.julialang.org/u/yuyichao)
#### Post date: [February 24, 2017, 9:46pm UTC](https://discourse.julialang.org/t/segmentation-fault-when-a-try-to-catch-a-interruptexception/2285/6 "2017-02-24T21:46:47Z")

</div>

It seems that you are running from a script and this is the expected behavior. Note that this is not a segfault.

---

<div class="post-metadata">

### Author: ![yuyichao](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/yuyichao/32/20_2.png) [@yuyichao](https://discourse.julialang.org/u/yuyichao)
#### Post date: [February 24, 2017, 9:52pm UTC](https://discourse.julialang.org/t/segmentation-fault-when-a-try-to-catch-a-interruptexception/2285/7 "2017-02-24T21:52:48Z")

</div>

Also note that in a script, you need to do `ccall(:jl_exit_on_sigint, Void, (Cint,), 0)` in order to turn a `SIGINT` into an exception. I have no idea why it is like this but it has been like this forever and doesn’t seem to be well documented…

---

<div class="post-metadata">

### Author: ![Alvaro\_M](https://avatars.discourse-cdn.com/v4/letter/a/b487fb/32.png) [@Alvaro\_M](https://discourse.julialang.org/u/Alvaro_M)
#### Post date: [February 24, 2017, 9:55pm UTC](https://discourse.julialang.org/t/segmentation-fault-when-a-try-to-catch-a-interruptexception/2285/8 "2017-02-24T21:55:02Z")

</div>

Yes, now in dev-0.6.0 doesn’t throw a segfault in 0.5.1 I still get a segfault.

Either way, I can’t catch the Interrupt exception with the script.

Update: The code works in the REPL.

---

<div class="post-metadata">

### Author: ![yuyichao](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/yuyichao/32/20_2.png) [@yuyichao](https://discourse.julialang.org/u/yuyichao)
#### Post date: [February 24, 2017, 10:42pm UTC](https://discourse.julialang.org/t/segmentation-fault-when-a-try-to-catch-a-interruptexception/2285/9 "2017-02-24T22:42:08Z")

</div>

See my comment above.

---

<div class="post-metadata">

### Author: ![Alvaro\_M](https://avatars.discourse-cdn.com/v4/letter/a/b487fb/32.png) [@Alvaro\_M](https://discourse.julialang.org/u/Alvaro_M)
#### Post date: [February 24, 2017, 10:48pm UTC](https://discourse.julialang.org/t/segmentation-fault-when-a-try-to-catch-a-interruptexception/2285/10 "2017-02-24T22:48:08Z")

</div>

Sorry, I didn’t read it.

It works now.

Thank you.
