Skip to content

Commit f7d2767

Browse files
committed
Document and add tests for "attempt"
1 parent a8e97ae commit f7d2767

File tree

3 files changed

+50
-1
lines changed

3 files changed

+50
-1
lines changed

M2/Macaulay2/packages/Macaulay2Doc/ov_debugging.m2

Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -327,6 +327,49 @@ 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. If the evaluation completes
355+
successfully, then the value is returned.
356+
Example
357+
attempt 5
358+
Text
359+
If an error occurs, then an @TO Error@ object containing information
360+
about the error is returned.
361+
Example
362+
attempt 1/0
363+
Text
364+
Note that this is a @TO Keyword@, not a method, and so it is not
365+
necessary to enclose @VAR "c"@ in parentheses.
366+
Example
367+
attempt 5 == "foo"
368+
{attempt error "bar", 1/2}
369+
attempt 1/0; 1/2
370+
SeeAlso
371+
symbol try
372+
///
330373

331374
document {
332375
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+
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)