Files
calc/help/newerror
Landon Curt Noll a6824debbc improved calc computation error codes message array
Changed calc_errno a global int variable so that is may be directly
accessed by libcalc users.

Further improve help files for help/errno, help/error, help/newerror,
help/stoponerror and help/strerror by adding to documentation
of the calc error code system as well as libcalc interface
where applicable.

Changed #define E_USERDEF to #define E__USERDEF.

Removed use of E_USERDEF, E__BASE, E__COUNT, and E__HIGHEST
from custom/c_sysinfo because the c_sysinfo is just a demo
and this will simplify the custom/Makefile.

The include file calcerr.h is now the errsym.h include file.
The calcerr.tbl has been replaced by errtbl.c and errtbl.h.

The calcerr_c.awk, calcerr_c.sed, calcerr_h.awk, and
calcerr_h.sed files are now obsolete and have been removed.
The calcerr.c and calcerr.h now obsolete and are no longer built.

The calc computation error codes, symbols and messages are now in
a error_table[] array of struct errtbl.

An E_STRING is a string corresponds to an error code #define.
For example, the E_STRING for the calc error E_STRCAT,
is the string "E_STRING".  An E_STRING must now match
the regular expression: "^E_[A-Z0-9_]+$".

The old array error_table[] of error message strings has been
replaced by a new error_table[] array of struct errtbl.  The struct
errtbl array holds calc errnum error codes, the related E_STRING
symbol as a string, and the original related error message.
To add new computation error codes, add them near the bottom of the
error_table[] array, just before the NULL entry.

The ./errcode utility, when run, will verify the consistency of
the error_table[] array.

The Makefile uses ./errcode -e to generate the contents of
help/errorcodes file.  The help errorcodes now prints
information from the new cstruct errtbl error_table[] array.

The help/errorcodes.hdr and help/errorcodes.sed files are
now obsolete and have been removed.

The Makefile uses ./errcode -d to generate the contents of the
errsym.h include file.

Updated .gitignore and trailblank to support the above changes.
2023-09-13 02:45:33 -07:00

102 lines
3.2 KiB
Plaintext

NAME
newerror - create or recall a user defined error condition
SYNOPSIS
newerror([str])
TYPES
str string
return error-value
DESCRIPTION
If str is not "" and has not earlier been used as an argument for
this function, newerror(str) creates a new described error-value so
that any future use of newerror(str) with the same str will return
the same error-value.
When this function is called, the global calc error count (see
help errcount) is incremented. If the global calc error count
exceeds the maximum count (see help errmax), any ongoing calc
execution is aborted.
If x = newerror(str), both strerror(x) and strerror(iserro(x)) will
return str and iserror(x) will return the error code value of the
new error.
The null cases newerror() and newerror("") are equivalent to
newerror("???").
EXAMPLE
Note that by default, errmax() is 0 so unless errmax() is
increased you will get:
; ba = newerror("curds n' whey");
Error 20000 caused errcount to exceed errmax
; errmax(errcount()+5)
0
; e1 = newerror("triangle side length <= 0")
; iserror(e1)
20000
; error(20000)
Error 20000
; strerror(error(20000))
"triangle side length <= 0"
; strerror(e1);
"triangle side length <= 0"
; strerror(error(iserror(e1)))
"triangle side length <= 0"
; 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 newerror("Non-triangle sides");
;; return sqrt(s * (s - a) * (s - b) * (s - c));
;; }
"area" defined
; A = area(8,2,5);
; if (iserror(A)) print strerror(A) : ":", iserror(A);
Non-triangle sides: 20001
; A = area(-3,4,5)
; if (iserror(A)) print strerror(A) : ":", iserror(A);
triangle side length <= 0: 20000
LIMITS
The number of new described error-values is not to exceed E__USERMAX-E__USERDEF
(which is usually 12767 calls to the newerror function).
E_STRING is string matching the regular expression: "^E_[A-Z0-9]+$"
LINK LIBRARY
none
SEE ALSO
errmax, errcount, error, strerror, iserror, errno, errorcodes,
stoponerror
## Copyright (C) 1999-2006,2023 Landon Curt Noll
##
## Calc is open software; you can redistribute it and/or modify it under
## the terms of the version 2.1 of the GNU Lesser General Public License
## as published by the Free Software Foundation.
##
## Calc is distributed in the hope that it will be useful, but WITHOUT
## ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
## or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General
## Public License for more details.
##
## A copy of version 2.1 of the GNU Lesser General Public License is
## distributed with calc under the filename COPYING-LGPL. You should have
## received a copy with calc; if not, write to Free Software Foundation, Inc.
## 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
##
## Under source code control: 1996/04/30 03:39:56
## File existed as early as: 1996
##
## chongo <was here> /\oo/\ http://www.isthe.com/chongo/
## Share and enjoy! :-) http://www.isthe.com/chongo/tech/comp/calc/