Project

General

Profile

Feature #92

Error Codes

Added by Anna Maria Bigatti about 12 years ago. Updated about 7 years ago.

Status:
In Progress
Priority:
Normal
Assignee:
-
Category:
Various
Target version:
Start date:
14 Feb 2012
Due date:
% Done:

0%

Estimated time:
40.00 h
Spent time:

Description

We've been talking a lot about how to classify errors and how many errors (error classes) we should have.
[see related issues below]

Here I have some cases:
DEFINE_ERROR(BadIndex, "Index out of range");
I think this should be called IndexOutOfRange

Another error I think would be useful in some occasions is "repeated index"


Related issues

Related to CoCoALib - Design #308: Error: ERR::NotNonZero instead of ERR::ZeroRingElem?In Progress2013-02-12

Related to CoCoALib - Feature #385: Design new errors using inheritanceIn Progress2013-07-08

Related to CoCoALib - Design #582: Error codes: use same code for "not poly ring" and "not elem poly ring"New2014-07-07

Related to CoCoALib - Feature #743: Better errors: give supplementary info about the errorIn Progress2015-06-30

Related to CoCoA-5 - Feature #1045: Error message from cocoalib to cocoa-5Closed2017-04-13

Related to CoCoALib - Design #427: Error names and error messages (current design)In Progress2014-01-28

Related to CoCoALib - Design #1063: Catching an (expected) errorClosed2017-05-09

History

#1 Updated by John Abbott over 11 years ago

  • Estimated time set to 40.00 h

The exception catching mechanism in C++ distinguishes the errors based on their types (respecting inheritance relationships). The current arrangement for errors in CoCoALib does not exploit inheritance at all, making it cumbersome for users who want to catch certain types of exception (they have to catch, do some comparisons, and possibly rethrow).

Redesign the CoCoALib error system to use inheritance; this implies organizing the errors into related groups. It may become less easy to add a new error (but this is probably a feature rather than a bug :-))

The hope is that we can also reduce the overall number of different exceptions CoCoALib throws.

#2 Updated by John Abbott over 11 years ago

Here is note for accumulating ideas for structuring CoCoALib exceptions:
(1) create CannotDivide which has two subclasses: InexactDivision and DivByZeroDivisor
(2) create IndexOutOfRange with subclasses BadRowIndex and BadColIndex

#3 Updated by John Abbott almost 11 years ago

Note: our current thinking is to have only very few types of error, and allow each error object to contain a supplementary message giving more details about what went wrong. Here are a few examples:
  • IndexOutOfRange with suppl mesg "matrix row index"
  • UnsuitableValue with suppl mesg "value must be >= 0"
  • BadType with suppl mesg "defined only for FractionFields"

Comparison of error objects will completely ignore the suppl mesg; so two IndexOutOfRange error objects with differing suppl mesgs will compare as equal. This is so that one can perform a check like if (ErrObj == IndexOutOfRange) ...; WARNING it may produce some unexpected results if error objects are used in std::map containers.

#4 Updated by John Abbott almost 11 years ago

What is a reasonable syntax for adjoining a suppl mesg to an error object?

(A) Anna suggests a fn-call style: IndexOutOfRange("matrix row")
(B) John suggests a binary op: IndexOutOfRange + "matrix row"
(B*) variant of proposal (B): IndexOutOfRange += "matrix row"
(C) BOOST uses a syntax like that for ostreams: IndexOutOfRange << "matrix row"

What happens if one tries to add several suppl mesgs?
(1) gives an error
(2) suppl mesgs are appended
(3) only the last suppl mesg is recorded
(4) only the first suppl mesg is recorded

JAA does not like option (1): getting an error while trying to prepare an error message is not ideal!! Option (2) is probably simplest to implement (and possibly the most natural) -- do we want to encourage/discourage appending multiple suppl mesgs? JAA thinks that the BOOST syntax encourages it.

NOTE (2013-09-11) if we want option (2) then JAA thinks syntax (B) or (B*) is more natural than syntax (A)

#5 Updated by Anna Maria Bigatti about 10 years ago

  • Target version set to CoCoALib-0.99533 Easter14

#6 Updated by John Abbott about 10 years ago

  • Target version changed from CoCoALib-0.99533 Easter14 to CoCoALib-1.0

#7 Updated by Anna Maria Bigatti about 7 years ago

There are some notes about "classes of errors" in the CoCoALib documentation for error, section "=== new improved list of errors ==="

#8 Updated by Anna Maria Bigatti about 7 years ago

  • Related to Feature #743: Better errors: give supplementary info about the error added

#9 Updated by Anna Maria Bigatti about 7 years ago

Anna Maria Bigatti wrote:

There are some notes about "classes of errors" in the CoCoALib documentation for error, section "=== new improved list of errors ==="

I suggest keeping the errors in error.C sorted as in that list (instead of the current alphabetical order): I believe that in this way, we would consider the problem of classifying the errors when we are thinking/looking for an error message, so when our brain is more likely to find a good strategy.

#10 Updated by Anna Maria Bigatti about 7 years ago

  • Related to Feature #1045: Error message from cocoalib to cocoa-5 added

#11 Updated by Anna Maria Bigatti about 7 years ago

  • Description updated (diff)
  • Status changed from New to In Progress

#12 Updated by Anna Maria Bigatti about 7 years ago

  • Related to Design #427: Error names and error messages (current design) added

#13 Updated by Anna Maria Bigatti almost 7 years ago

  • Related to Design #1063: Catching an (expected) error added

Also available in: Atom PDF