# Missed the WAT thread, so here's one for intentionally cursed code

**URL:** <https://discourse.julialang.org/t/missed-the-wat-thread-so-heres-one-for-intentionally-cursed-code/114446>\
**Category:** Offtopic\
**Tags:** joke\
**Created:** [May 19, 2024, 4:40am UTC](https://discourse.julialang.org/t/missed-the-wat-thread-so-heres-one-for-intentionally-cursed-code/114446 "2024-05-19T04:40:02Z")\
**Posts on this page:** 3\
**Page:** 2

<div class="post-metadata">

**Author:** ![miguelraz](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/miguelraz/32/631_2.png) [@miguelraz](https://discourse.julialang.org/u/miguelraz)\
**Post date:** [May 22, 2024, 6:03pm UTC](https://discourse.julialang.org/t/missed-the-wat-thread-so-heres-one-for-intentionally-cursed-code/114446/21 "2024-05-22T18:03:23Z")

</div>

I hate/love this so much.

To the list it goes.

---

<div class="post-metadata">

**Author:** ![cpfiffer](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/cpfiffer/32/208747_2.png) [@cpfiffer](https://discourse.julialang.org/u/cpfiffer)\
**Post date:** [May 22, 2024, 9:30pm UTC](https://discourse.julialang.org/t/missed-the-wat-thread-so-heres-one-for-intentionally-cursed-code/114446/22 "2024-05-22T21:30:38Z")

</div>

Fantastic thread

---

<div class="post-metadata">

**Author:** ![Benny](https://avatars.discourse-cdn.com/v4/letter/b/49beb7/32.png) [@Benny](https://discourse.julialang.org/u/Benny)\
**Post date:** [May 23, 2024, 1:59am UTC](https://discourse.julialang.org/t/missed-the-wat-thread-so-heres-one-for-intentionally-cursed-code/114446/23 "2024-05-23T01:59:14Z")

</div>

> [@mrufsvold](#):
>
> If the error is not one of `ExpectedErrorType` or `AnotherErrorType`, Python falls back to rethrowing the error. It is considered bad practice in Python to do `except:` and generically handle all exceptions.

To expand on this, another angle is that without `else rethrow()`, Julia’s bare `catch` “falls back” to continuing after a `if-elseif` exception type block. One could argue this is equally valid default behavior, like returning `nothing` for the “cursed” `sqrt_second`, but PEP8 argues:

> A bare `except:` clause will catch SystemExit and KeyboardInterrupt exceptions, making it harder to interrupt a program with Control-C, and can disguise other problems. If you want to catch all exceptions that signal program errors, use `except Exception:` (bare except is equivalent to `except BaseException:` ).

To explain `BaseException`, PEP352 introduced another layer of hierarchy to separate some lower-level exceptions from the run-of-the-mill `Exception` superclass in case the user does want generic handling of the latter; I wouldn’t call `except Exception:` default behavior because a subset is specified. I don’t know if there’s something similar in Julia, but we wouldn’t need to change our flatter `Exception` hierarchy with an extra defined supertype because we have `Union`.

> BaseException # Julia’s equivalent is just called Exception  
> ├── BaseExceptionGroup  
> ├── GeneratorExit  
> ├── KeyboardInterrupt  
> ├── SystemExit  
> └── Exception  
> … …├── …

I personally agree that Control-C should simply stop the program unless `InterruptException` is specifically handled, so rethrowing makes more sense as a default behavior for caught exceptions over continuing. Here’s an example where the `InterruptException` gets caught and risks continuing:

```julia
function foo(t=3.0) # t gives time to Control-C
  try
    sleep(t) # Control-C gets caught
    div(1,0)
  catch
    println("catching...")
    sleep(t) # now Control-C stops the program
  end
  "foo end"
end

```

[Previous page](https://discourse.julialang.org/t/missed-the-wat-thread-so-heres-one-for-intentionally-cursed-code/114446.md?page=1)
