[ RDocumentation ](/)

Moon  [ ](https://github.com/datacamp/rdocumentation-2.0) [ Learn R
](https://www.datacamp.com/learn/r)

Search all packages and functions

[ base  (version  3.6.2  ) ](/packages/base/versions/3.6.2)

#  stop: Stop Function Execution

##  Description

` stop ` stops execution of the current expression and executes an error
action.

` geterrmessage ` gives the last error message.

##  Usage

    
    
    stop(…, call. = TRUE, domain = NULL)
    geterrmessage()

##  Arguments

…

zero or more objects which can be coerced to character (and which are pasted
together with no separator) or a single condition object.

call.

logical, indicating if the call should become part of the error message.

domain

see ` [ gettext ](/link/gettext?package=base&version=3.6.2) ` . If ` NA ` ,
messages will not be translated.

##  Value

` geterrmessage ` gives the last error message, as a character string ending
in ` "\n" ` .

##  Details

The error action is controlled by error handlers established within the
executing code and by the current default error handler set by `
options(error=) ` . The error is first signaled as if using ` [
signalCondition ](/link/signalCondition?package=base&version=3.6.2) () ` . If
there are no handlers or if all handlers return, then the error message is
printed (if ` options("show.error.messages") ` is true) and the default error
handler is used. The default behaviour (the ` NULL ` error-handler) in
interactive use is to return to the top level prompt or the top level browser,
and in non-interactive use to (effectively) call ` [ q
](/link/q?package=base&version=3.6.2) ("no", status = 1, runLast = FALSE ` ).
The default handler stores the error message in a buffer; it can be retrieved
by ` geterrmessage() ` . It also stores a trace of the call stack that can be
retrieved by ` [ traceback ](/link/traceback?package=base&version=3.6.2) () `
.

Errors will be truncated to ` getOption("warning.length") ` characters,
default 1000.

If a condition object is supplied it should be the only argument, and further
arguments will be ignored, with a warning.

##  References

Becker, R. A., Chambers, J. M. and Wilks, A. R. (1988) _The New S Language_ .
Wadsworth & Brooks/Cole.

##  See Also

` [ warning ](/link/warning?package=base&version=3.6.2) ` , ` [ try
](/link/try?package=base&version=3.6.2) ` to catch errors and retry, and ` [
options ](/link/options?package=base&version=3.6.2) ` for setting error
handlers. ` [ stopifnot ](/link/stopifnot?package=base&version=3.6.2) ` for
validity testing. ` tryCatch ` and ` withCallingHandlers ` can be used to
establish custom handlers while executing an expression.

` [ gettext ](/link/gettext?package=base&version=3.6.2) ` for the mechanisms
for the automated translation of messages.

##  Examples

[ Run this code
](https://app.datacamp.com/workspace/preview?_tag=rdocs&rdocsPath=packages%2Fbase%2Fversions%2F3.6.2%2Ftopics%2Fstop&utm_source=r-docs&utm_medium=docs&utm_term=stop&utm_content=run_example_in_workspace)

    
    
    # NOT RUN {
    iter <- 12
    try(if(iter > 10) stop("too many iterations"))
    
    tst1 <- function(...) stop("dummy error")
    try(tst1(1:10, long, calling, expression))
    
    tst2 <- function(...) stop("dummy error", call. = FALSE)
    try(tst2(1:10, longcalling, expression, but.not.seen.in.Error))
    # }
    

Run the code above in your browser using  [ DataCamp Workspace
](https://app.datacamp.com/workspace/preview?_tag=rdocs&rdocsPath=packages%2Fbase%2Fversions%2F3.6.2%2Ftopics%2Fstop&utm_source=r-docs&utm_medium=docs&utm_term=stop&utm_content=run_example_in_workspace)

Powered by  [ DataCamp ](https://www.datacamp.com/)