How to quit the entire program in Julia

Viewed 474

How can I quit the entire program like this in Julia? (this is in Python):

import sys

def some_func():
   # do something
   sys.exit()

Thank you!

2 Answers

You do not need to import Base for exiting; you can just use exit:

function some_func()
    # do something
    exit() # <- you can provide exit code if you want.
end

I'll warn you that Stack Overflow is notoriously hostile to questions like these, that demonstrate that you've not attempted to research the answer to this question before coming to Stack Overflow for help. I say this only to give you a heads up about the sorts of responses that you'll normally receive on this platform, not necessarily because I think that's how it should be. When I googled "julia exit program", the answer was one of the top four results.

All that being said, here's how you do it:

import Base
Base.exit(exit_code)

...where exit_code is the number you wish to exit with. If you omit it, it defaults to zero.

Related