check (+)
![]() Curtis L. Brown Jr., STS-95 commander, checks over notes with Houston ground controllers. October 31, 1998 NASA | check throws exceptions if the given math expression argument resolves to False, otherwise it takes no action. It is the tool of choice for checking command arguments, taking math expressions that resolve to True with arguments that possess must-have features. If any calling scope encompasses a local … done block with an onfail section, the exception is caught and further processing resumes in the -onfail section. Otherwise -check uses its argument for the exception message and exits G'MIC. Since 2.6, -check no longer directly tests for file system objects; use math expressions isfile() or isdir() instead. Consider using error if a custom message is desired. Since -error unconditionally throws exceptions, combine it with conditional commands to emulate -check, but in (probably) a less compact way. |
Examples
$ gmic check 0 echo 'Done!'
[gmic]-0./ Start G'MIC interpreter.
[gmic]-0./ *** Error *** Command 'check': Expression '0' evaluated to false.
$ gmic check 1 echo 'Fooooo!'
[gmic]-0./ Start G'MIC interpreter.
[gmic]-0./ Fooooo!
[gmic]-0./ End G'MIC interpreter.
[gmic]-0./ Start G'MIC interpreter.
[gmic]-0./ *** Error *** Command 'check': Expression '0' evaluated to false.
$ gmic check 1 echo 'Fooooo!'
[gmic]-0./ Start G'MIC interpreter.
[gmic]-0./ Fooooo!
[gmic]-0./ End G'MIC interpreter.
display_graph : check "${1=0}>=0 && ${2=0}>=0" …
dg : check "${1=0}>=0 && ${2=0}>=0" skip ${3=1},${4=0},${5=0},${6=0},${7=0},${8=0},"${9=x-axis}","${10=y-axis}"…
dg : check "${1=0}>=0 && ${2=0}>=0" skip ${3=1},${4=0},${5=0},${6=0},${7=0},${8=0},"${9=x-axis}","${10=y-axis}"…
Combine skip with check to set custom command arguments to default values, but exclude such from -check processing. Effectively, this creates an optional argument that has a default value.
onfail.gmic
Wrapping -check within an onfail section of a local … done block may lead to a more adroit handling of thrown exceptions, not the least of which being posting purpose-specific error messages or saving of already-generated images from the effects of an inopportune exception. This approach is not peculiar to -check but to any circumstance where an exception is possible.
sameas :
left=$1
right=$2
-local
-testit $left,$right
-echo $left" is the same as "$right"."
-onfail
-echo $left" differs from "$right"."
-quit
-done
testit : -check "${1}==${2}"
§§§
$ gmic onfail.gmic sameas 3,3
[gmic]-0./ Start G'MIC interpreter.
[gmic]-0./ Input custom command file 'onfail.gmic' (2 new, total: 4447).
[gmic]-0./sameas/*local/ 3 is the same as 3.
[gmic]-0./ End G'MIC interpreter.
$ gmic onfail.gmic sameas 4,3
[gmic]-0./ Start G'MIC interpreter.
[gmic]-0./ Input custom command file 'onfail.gmic' (2 new, total: 4447).
[gmic]-0./sameas/*local/ 4 differs from 3.
left=$1
right=$2
-local
-testit $left,$right
-echo $left" is the same as "$right"."
-onfail
-echo $left" differs from "$right"."
-quit
-done
testit : -check "${1}==${2}"
§§§
$ gmic onfail.gmic sameas 3,3
[gmic]-0./ Start G'MIC interpreter.
[gmic]-0./ Input custom command file 'onfail.gmic' (2 new, total: 4447).
[gmic]-0./sameas/*local/ 3 is the same as 3.
[gmic]-0./ End G'MIC interpreter.
$ gmic onfail.gmic sameas 4,3
[gmic]-0./ Start G'MIC interpreter.
[gmic]-0./ Input custom command file 'onfail.gmic' (2 new, total: 4447).
[gmic]-0./sameas/*local/ 4 differs from 3.
Command reference
$ gmic -h check
check (+):
condition
Evaluate specified condition and display an error message if evaluated to false.
check (+):
condition
Evaluate specified condition and display an error message if evaluated to false.