Wolfram Research

AbortOnMessage

Contributed by: Richard Hennigan

Abort an evaluation as soon as a message is generated

ResourceFunction["AbortOnMessage"][eval]

aborts evaluation of eval if a message occurs.

ResourceFunction["AbortOnMessage"][eval,quiet]

aborts on message but disregards messages in quiet.

ResourceFunction["AbortOnMessage"][eval,quiet,listen]

forces an abort for any message in listen, even if it is quieted.

Examples

Basic Examples

Use the function:

In[1]:=
ResourceFunction["AbortOnMessage"][Table[First[1], 5]]
Out[1]=

More Examples

Scope

Retrieve the ResourceFunction:

In[2]:=
ResourceFunction["AbortOnMessage"]
Out[2]=

Retrieve the ResourceObject:

In[3]:=
ResourceObject["AbortOnMessage"]
Out[3]=

Ignore some messages:

In[4]:=
ResourceFunction["AbortOnMessage"][
 Table[First[1], 5], {First::normal}]
Out[4]=

Trigger an abort even if a message is quieted:

In[5]:=
ResourceFunction["AbortOnMessage"][
 Quiet[Table[First[1], 5], {First::normal}], None, {First::normal}]
Out[5]=

Properties and Relations

AbortOnMessage will stop an evaluation rather than just suppress additional messages:

In[6]:=
ResourceFunction["AbortOnMessage"][
 Table[Print[Last[Range[-n]]], {n, -2, 2}]]
Out[6]=

Possible Issues

Any messages given in the third argument will take precedence over the second argument:

In[7]:=
ResourceFunction["AbortOnMessage"][
 Table[First[1], 5], {First::normal}, {}]
Out[7]=
In[8]:=
ResourceFunction["AbortOnMessage"][
 Table[First[1], 5], {First::normal}, {First::normal}]
Out[8]=

Resource History