I am calling a function that I terminate using TimeConstrained[]
if the function doesn't complete in some time. Since TimeConstrained[]
returns $Aborted
, I thought I will use CheckAbort[]
to test for Abort signal and return a default value on failure. I am unable to understand the behavior of CheckAbort[]. As Abort[]
and TimeContrained[]
both return the special symbol $Aborted
, I assumed that the behavior would be the same. I expected the variable test
to have value 0
in both cases below but the behavior is confusing.
test = CheckAbort[TimeConstrained[Pause[2], 1], 0]
test = CheckAbort[Abort[], 0]
Output:
$Aborted
0
TimeConstrained[Pause[2], 1, 0]
. $\endgroup$TimeConstrained
andCheckAbort
not being on speaking terms is a long-standing one. I am optimistic that it will finally resolved in the version 12.2 time frame. For now the approach in the response by @Nasser seems like a viable workaround. $\endgroup$