Abort: Difference between revisions

From Kolmafia
Jump to navigation Jump to search
imported>StDoodle
mNo edit summary
imported>StDoodle
mNo edit summary
Line 14: Line 14:
if (my_name() != "MrPicky") {
if (my_name() != "MrPicky") {
   abort("I don't want you to run this script, mister!");
   abort("I don't want you to run this script, mister!");
}
</syntaxhighlight>}} |
code2={{CodeSample |
description=An example of '''abort()''' used for error-handling.|
code=
<syntaxhighlight lang="c">
float mass = 5.0;
float volume = some_function(); //where some_function() returns 0.0
float density;
if (volume_cf == 0) {
  abort("Error: Division by zero requested.");
} else {
  density = mass / volume;
}
}
</syntaxhighlight>}} |
</syntaxhighlight>}} |
cli_equiv=Also available as the CLI command "abort," which will not be queued (similarly stops execution of all remaining commands when parsed).
cli_equiv=Also available as the CLI command "abort," which will not be queued (similarly stops execution of all remaining commands when parsed).
}}
}}

Revision as of 13:29, 25 February 2010

Function Syntax

Halts all queued functions and the entire script it is called from. Often used for error-handling.

Code Sample

This code will abort the script if run by the "wrong" character.

if (my_name() != "MrPicky") {
  abort("I don't want you to run this script, mister!");
}

An example of abort() used for error-handling.

float mass = 5.0;
float volume = some_function(); //where some_function() returns 0.0
float density;
if (volume_cf == 0) {
  abort("Error: Division by zero requested.");
} else {
  density = mass / volume;
}

CLI Equivalent

Also available as the CLI command "abort," which will not be queued (similarly stops execution of all remaining commands when parsed).