How to stop execution in my program

后端 未结 2 1531
有刺的猬
有刺的猬 2020-12-21 02:10

Without copy-pasting my code here, how can I stop my ADA program from executing anymore lines of code during run-time if it calculates a certain value to \'X\'?

some

2条回答
  •  青春惊慌失措
    2020-12-21 02:16

     if variable_name >1 then
        raise PROGRAM_ERROR with "Aborted because ...";
     end if;
    

    will do what you ask. Whether that's what you want is another matter, you haven't given us enough context to guess at that.

    The "abort" statement might also be usable, but its normal role is terminating tasks within a multi-tasking program.

    Raising an exception is probably easiest, and if you don't like the standard ones, you can always declare your own. With an exception you can also do any tidying up (such as closing files if you need to) in your own exception handler. See the Wikibook for more details.

提交回复
热议问题