mirror of
https://github.com/lcn2/calc.git
synced 2025-08-19 01:13:27 +03:00
40 lines
837 B
Plaintext
40 lines
837 B
Plaintext
NAME
|
|
newerror - create a new error type
|
|
|
|
SYNOPSIS
|
|
newerror([str])
|
|
|
|
TYPES
|
|
str non-null string
|
|
|
|
return error-value
|
|
|
|
DESCRIPTION
|
|
With or without an argument, newerror() creates an error-value
|
|
different from already existing error-values. With the argument
|
|
str, if x == newerror(str), strerror(iserror(x)) returns str.
|
|
|
|
EXAMPLE
|
|
> e1 = newerror("Non-positive side")
|
|
> e2 = newerror("Non-triangle sides")
|
|
|
|
> define area(a,b,c) {\
|
|
> local s;\
|
|
> if (!(a > 0) || !(b > 0) || !(c > 0)) return e1;\
|
|
> s = (a + b + c)/2;\
|
|
> if (s <= a || s <= b || s <= c) return e2;\
|
|
> return sqrt(s * (s - a) * (s - b) * (s - c)); }
|
|
|
|
> print strerror(iserror(area(8,2,5)))
|
|
|
|
Non-triangle sides
|
|
|
|
LIMITS
|
|
none - XXX - is this correct?
|
|
|
|
LIBRARY
|
|
none
|
|
|
|
SEE ALSO
|
|
errorcodes, iserror, error
|