Stop(msg) Julia Program

could you add a stop(msg) function that works like error(msg), but replaces the word ERROR with STOP and does not print a stack backtrace?

/iaw

It might be better to describe your use case and ask for a way to implement it using currently available language features (in Usage category). From multiple discussions here and on GitHub you can see that most core devs are overloaded working on Julia 0.7/1.0, and even beyond that they have a long, long list of desired features, so bringing another one without a good use case for many people is unlikely to get a response.

Yet, as you should’ve already noticed, Julia community is friendly and helps to solve many practical problems without changing the language.

(And if the problem is unsolvable in the current language, the best strategy for bringing a new feature is to make a pull request)

What about

struct Stop <: Exception end
Base.display_error(io::IO, ::Stop, _) = println(io, "STOP")
stop() = throw(Stop())

eg

julia> f() = stop()
f (generic function with 1 method)

julia> f()
STOP

PS.: I realized I forgot the message. Left as an exercise for the reader :wink:

8 Likes

holy cow. this was easier than I thought. thanks, tamas.

It seems that the @Tamas_Papp solution is not fully working in the last Julia version since the stack trace is still printed and the message not.