This answer assumes that with "debugging error" you mean that Message has been released. For example, a message is issued as a warning if you try to divide by zero:
In[1]:= Print[1/0] Power::infy: Infinite expression 1/0 encountered. >> ComplexInfinity
Note that ComplexInfinity was printed by the Print statement, even though a warning message was issued indicating that the calculation continues after an βerrorβ.
I wonβt reuse @Sjoerd's excellent answer, which shows how to set up a Mathematica session so that the kernel exits if any message fails with an evaluation. If you want to be more selective and get out of the kernel only if a particular rating triggers a message, then the following function may be useful:
ClearAll[checkQuit] SetAttributes[checkQuit, HoldFirst] checkQuit[expr_, HoldPattern[messages_:Sequence[]]] := Check[expr, Message[checkQuit::quit]; Quit[], messages] checkQuit::quit = "The kernel is being shut down!";
Using this definition, you can make the kernel fail after a message is issued with a specific rating:
In[37]:= checkQuit[Print[1/0]] Power::infy: Infinite expression 1/0 encountered. >> checkQuit::quit: The kernel is being shut down!
If it can only be convenient to exit the kernel if certain messages are released. To this end, checkQuit accepts an optional second argument, which can be used to indicate messages of interest:
In[6]:= checkQuit[{}[[10]], Power::infy] Part::partw: Part 10 of {} does not exist. >> Out[6]= {}[[10]]
Note that the kernel was not output, as the message did not match Power::infy . But note:
In[7]:= checkQuit[1/0, Power::infy] Power::infy: Infinite expression 1/0 encountered. >> checkQuit::quit: The kernel is being shut down!
Here, the kernel terminates because the specified message appears. You can filter multiple messages or even predefined message groups. See Check for details.