Mathematica has the CheckAbort
function which allows to catch and handle user-generated and programmatic Abort
s. But it does not allow to catch interrupts generated by such functions as TimeConstrained
and MemoryConstrained
:
TimeConstrained[CheckAbort[Pause[100], Print["From CheckAbort"]], 1]
(does not print "From CheckAbort"
).
Is there a way to catch such interrupts in Mathematica?
EDIT: I do know that third argument of TimeConstrained
and MemoryConstrained
allows to evaluate some code in the case of interrupt but this way is not what I need: I need a way to handle such interrupts entirely inside of my function allowing a user do not care of its internals.
P.S. The reason why I need this is that I have a function that creates MathLink
objects which must be closed in the case of any interrupts or aborts but not in other cases.