# A Julia equivalent to R's stop()?

**URL:** https://discourse.julialang.org/t/a-julia-equivalent-to-rs-stop/36568
**Category:** New to Julia
**Tags:** question
**Created:** [March 26, 2020, 9:40pm UTC](https://discourse.julialang.org/t/a-julia-equivalent-to-rs-stop/36568 "2020-03-26T21:40:53Z")
**Posts on this page:** 1
**Showing post:** 5

<div class="post-metadata">

### Author: ![pixel27](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/pixel27/32/8902_2.png) [@pixel27](https://discourse.julialang.org/u/pixel27)
#### Post date: [March 26, 2020, 10:53pm UTC](https://discourse.julialang.org/t/a-julia-equivalent-to-rs-stop/36568/5 "2020-03-26T22:53:02Z")

</div>

You could probably do something like:

```julia
struct Stop{T}
    answer::T
end

function stop(answer)
    throw(Stop(answer))
end

function start()
    stop(42)
end

try
    start()
    @info "No answer."
catch ex
    if isa(ex, Stop)
        @info "Exit with: $(ex.answer)"
    else
        rethrow(ex)
    end
end

```

This assumes that you are not already catching exceptions in the stack. If you are then you probably want to throw a “Stop” object that the other exception handlers can rethrow.

This is also not the approved way of unwinding the stack, throw is meant for errors not a normal exit.

---

_[View the full topic](https://discourse.julialang.org/t/a-julia-equivalent-to-rs-stop/36568)._
