How to create an exit message

前端 未结 4 1828
刺人心
刺人心 2020-12-12 13:14

Is there a one line function call that quits the program and displays a message? I know in Perl it\'s as simple as:

die(\"Message goes here\")
4条回答
  •  南笙
    南笙 (楼主)
    2020-12-12 14:04

    If you want to denote an actual error in your code, you could raise a RuntimeError exception:

    raise RuntimeError, 'Message goes here'
    

    This will print a stacktrace, the type of the exception being raised and the message that you provided. Depending on your users, a stacktrace might be too scary, and the actual message might get lost in the noise. On the other hand, if you die because of an actual error, a stacktrace will give you additional information for debugging.

提交回复
热议问题