# Tag Info

5

How about using "RuntimeErrorHandler": f = Compile[{{x, _Real}, {y, _Real}}, Log[(x - y^2 - 2. x)^2]/(y x^2 - 2 (x + y) - y^2 + 3.), "RuntimeOptions" -> {"RuntimeErrorHandler" -> Function[Throw[$Failed]]} ]; Catch[Quiet@f[-196, 15]] // AbsoluteTiming (* {0.000019, 0.0000116843} *) Catch[Quiet@f[-196, 14]] // AbsoluteTiming (* {0.000051, ... 4 I use \$MessagePrePrint = StandardForm since without that the real number 1.5 is displayed in a message as 1.5. However, you might have \$MessagePrePrint set to something else. Check is used to control what should happen when a built-in message occurs. Quiet prevents the built-in message from being displayed. I made a pure function (i.e. #1,#2,& ...

3

A simple way would be to assign the value of expr to a variable and then return that variable after printing the messages. For example: info::values = "n was  and d was "; Module[{n, d, v} , n = 100 ; d = 0 ; Check[v = n / d, Message[info::values, n, d]; v] ]

3

One can define a dynamic environment where Message will be overloaded. Here is one way: ClearAll[withMessageDetection]; SetAttributes[withMessageDetection, HoldAll]; withMessageDetection[code_] := InternalInheritedBlock[{Message}, Module[{inMessage, tag}, Unprotect[Message]; (call : Message[args___]) /; ! TrueQ[inMessage] := ...

Only top voted, non community-wiki answers of a minimum length are eligible