Project

General

Profile

Feature #426

ConvertTo with optional arg to give more helpful error message

Added by John Abbott about 10 years ago. Updated about 10 years ago.

Status:
Closed
Priority:
Normal
Assignee:
Category:
Tidying
Target version:
Start date:
27 Jan 2014
Due date:
% Done:

100%

Estimated time:
2.50 h
Spent time:

Description

The ConvertTo fn is used extensively in the interface between the C5 interpreter and the CoCoALin fns which actually do the work. To improve readability of this code Anna proposes adding a variant of ConvertTo which accepts a 2nd arg, being a CoCoA::ErrorInfo object containing the error which should be thrown if conversion fails (thus allowing more meaningful messages to appear in C5).


Related issues

Related to CoCoALib - Feature #233: AsINT and AsRAT -- ConvertTo<BigInt> and ConvertTo<BigRat>Closed2012-09-25

Related to CoCoA-5 - Feature #317: BuiltInFunctions: evalArgAsLongClosed2013-02-20

Related to CoCoALib - Feature #61: Conversion functions -- documentationClosed2011-12-13

History

#1 Updated by Anna Maria Bigatti about 10 years ago

  • Status changed from New to Feedback
  • Assignee set to John Abbott
  • Target version set to CoCoALib-0.9953
  • % Done changed from 0 to 90

Jon implemented this and forgot to say it?
anyway it is very nice:
code was

    long n;
    if (!IsConvertible(n, NumIndets)) CoCoA_ERROR(ERR::ArgTooBig, "RingQQt");
    return RingQQt(n);
now is
    const ErrorInfo ErrMesg(ERR::ArgTooBig, "RingQQt");
    return RingQQt(ConvertTo<long>(NumIndets, ErrMesg));
it can be done in a single line, but this is more readable.
Of course this means that we are always creating the error message (instead of only when the error occurs), but I find the code much more readable (therefore maintanable).

#2 Updated by Anna Maria Bigatti about 10 years ago

added example and documentation (cvs-ed)

#3 Updated by Anna Maria Bigatti about 10 years ago

  • Target version changed from CoCoALib-0.9953 to CoCoALib-0.99532

#4 Updated by Anna Maria Bigatti about 10 years ago

  • Status changed from Feedback to Closed
  • % Done changed from 90 to 100

We are all happy about this. Tested and documented. Closing.

#5 Updated by Anna Maria Bigatti about 10 years ago

  • Estimated time set to 2.50 h

Also available in: Atom PDF