Skip to content

Commit 3e074f7

Browse files
committed
Document and add tests for "attempt"
1 parent f22c578 commit 3e074f7

File tree

3 files changed

+52
-1
lines changed

3 files changed

+52
-1
lines changed

M2/Macaulay2/packages/Macaulay2Doc/ov_debugging.m2

Lines changed: 45 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -327,6 +327,51 @@ document {
327327
}
328328
}
329329

330+
doc ///
331+
Key
332+
Error
333+
Headline
334+
error information
335+
Description
336+
Text
337+
An instance of this class is a hash table containing the position and
338+
message of an error caught by @TO symbol attempt@.
339+
Example
340+
attempt 1/0
341+
SeeAlso
342+
symbol attempt
343+
///
344+
345+
doc ///
346+
Key
347+
symbol attempt
348+
Headline
349+
attempt to evaluate code and get information about any errors that occur
350+
Usage
351+
attempt c
352+
Description
353+
Text
354+
The code @VAR "c"@ is evaluated and a sequence containing two elements
355+
is returned. If the evaluation completes successfully, then the first
356+
element is the value and the second element is null.
357+
Example
358+
attempt 5
359+
Text
360+
If an error occurs, then the first element is null and the second element
361+
is an @TO Error@ object containing information about the error is
362+
returned.
363+
Example
364+
attempt 1/0
365+
Text
366+
Note that this is a @TO Keyword@, not a method, and so it is not
367+
necessary to enclose @VAR "c"@ in parentheses.
368+
Example
369+
attempt 5 == "foo"
370+
{attempt error "bar", 1/2}
371+
attempt 1/0; 1/2
372+
SeeAlso
373+
symbol try
374+
///
330375

331376
document {
332377
Key => "recursionLimit",

M2/Macaulay2/packages/Macaulay2Doc/ov_language.m2

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -704,6 +704,8 @@ document {
704704
TO "error",
705705
TO "try",
706706
TO "throw",
707+
TO "attempt",
708+
TO "Error",
707709
}
708710
}
709711

@@ -733,7 +735,8 @@ document {
733735
"The behavior of interrupts (other than alarms) is unaffected.",
734736
EXAMPLE "apply(-3..3,i->try 1/i else infinity)",
735737
Caveat => "We will change the behavior of this function soon so that it will be possible to catch errors of a particular type. Meanwhile, users are
736-
recommended to use this function sparingly, if at all."
738+
recommended to use this function sparingly, if at all.",
739+
SeeAlso => {"attempt"},
737740
}
738741

739742
document {

M2/Macaulay2/tests/normal/error-messages.m2

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,6 @@
1+
(val, err) = attempt error "foo"
2+
assert Equation(err#"message", "foo")
3+
14
stderr << "--testing the error messages must be done manually" << endl
25
end
36

0 commit comments

Comments
 (0)