How to Quiet[] only the first argument of Check[]?
Mmm, something like this?
ClearAll[try]
SetAttributes[try, HoldAllComplete]
try[expr_, failexpr_, messages : {___MessageName} | PatternSequence[]] := Module[
{tag},
ReleaseHold @ Catch[
Quiet[
Check[
HoldComplete[#]& @ expr,
Throw[HoldComplete[failexpr], tag],
messages
],
messages
],
tag
]
]
A simple way to achieve the desired effect would be to write:
Quiet@Check[expr, $Failed, {NIntegrate::slwcon}] /. $Failed :> failexpr
If we are worried about a collision with the symbol $Failed
, we can choose a different symbol or generate a new one, e.g.
Module[{failed}
, Quiet@Check[expr, failed, {NIntegrate::slwcon}] /. failed :> failexpr
]