Some macros were introduced in order to make error handling more consistent and useful both from the developer's and the scanner operator's point of view. Here we describe the suggested method to use when programming with KSFoundation.
When an error is detected in the code, the programmer is encouraged to use the newly introduced macro KS_THROW – e.g.
The macro KS_THROW is a wrapper around ks_error and prepends to the error message the function name, file name and line number of the KS_THROW in order to easily find where the error occurred.
Regarding the error message, it should be chosen short enough so that it can be read in the scanner UI. If more information is needed, it can be added at the start of the error messsage followed by a semi colon. This is because ks_error removes everything up to the last semi colon when passing the error message to the UI. For instance, we can modify the example above as following:
and the error message in the UI will be unchanged but the extra information is stored in ks_errors.txt.
When calling a function that returns a STATUS value, usage of the macro KS_RAISE is encouraged – e.g.
In this manner the entire stack trace from the function where the error originally occurred up to the currently running top-level function will be recorded in ks_debug.txt.
Alternatively, one might want to clarify the error condition relative to the local context. In this case it is fine to call again KS_THROW as in the following:
The above is also recommended when calling a GE's function that return a STATUS as GE's uses a different logging system for errors and it would otherwise result in an incomplete stack trace in ks_debug.txt.