Feature #101
rethrow in Try .. UponError .. EndTry
Description
What is the way to deal with errors we don't want to catch?
See this example:
Define MyDeg(F) Try D := Deg(F); Return D; UponError E Do If "Non-zero RingElem required" IsIn GetErrMesg(E) Then Return -123456; Else error(GetErrMesg(E)); EndIf; EndTry; EndDefine;
So MyDeg(zero(R)) is caught and MyDeg("a") is an error, but
ERROR: Expecting type RINGELEM, but found type STRING error(GetErrMesg(E)); ^^^^^^^^^^^^^^^^^^^^
is it possible to have a better location or all the information is lost when using Try?
Related issues
History
#1 Updated by Giovanni Lagorio about 12 years ago
I'm afraid that information is lost at the moment (the error object contains the error message only, more information should be embedded there to allow a later re-throw of the "same" error)
#2 Updated by Anna Maria Bigatti about 12 years ago
Giovanni Lagorio wrote:
(the error object contains the error message only, more information should be embedded there to allow a later re-throw of the "same" error)
Can you estimate how difficult it would be to add the information? i.e. is there any hope for me to make it?
#3 Updated by John Abbott over 11 years ago
What is the correct way to write a CoCoA-5 test which checks that a certain call produces the expected error? It should complain if an error different from the expected one is encountered.
#4 Updated by Anna Maria Bigatti over 11 years ago
What about this?
(note that, as said above, all other error information is lost :-( )
Define CheckErrMesg(F, Arg1, SubstringErrMesg) Try IgnoreValue := F(Arg1); UponError e Do If Not (SubstringErrMesg IsIn GetErrMesg(e)) Then Error("EXPECTED Error: " + GetErrMesg(e)); EndIf; EndTry; EndDefine; -- CheckErrMesg CheckErrMesg(deg, 0*x, "Non-zero"); CheckErrMesg(deg, 0*x, "aksdhfkl");
Note: this is valid only for functions (not procedures) which expect just 1 arg. Anna suggests modifying it to accept a list of args (up to length 3?), and then use a cascade of If to call the function in the right way.
2012-12-12 JAA nice idea -- let's try it!
#5 Updated by Anna Maria Bigatti almost 10 years ago
- Target version set to CoCoA-5.1.0 Easter14
#6 Updated by John Abbott almost 10 years ago
- Target version changed from CoCoA-5.1.0 Easter14 to CoCoA-5.?.?
#7 Updated by John Abbott over 3 years ago
Have we used the idea in comment 4 in the CoCoA-5 tests?
I think probably not. If not, why not?
Solving the original problem looks like it would be hard and lengthy... I don't want to try :-(
I also wonder whether it is correct to solve the original problem. It might be slightly helpful during debugging, but otherwise...??
#8 Updated by John Abbott over 3 years ago
- Subject changed from Try .. UponError .. EndTry to rethrow in Try .. UponError .. EndTry