% Generated by roxygen2: do not edit by hand
% Please edit documentation in R/model.R
\name{with_rtmb_error_handling}
\alias{with_rtmb_error_handling}
\title{Catch and Translate RTMB Errors into User-Friendly Messages}
\usage{
with_rtmb_error_handling(expr, block_name)
}
\arguments{
\item{expr}{An R expression to be evaluated, typically representing the logic within
a specific model block.}

\item{block_name}{A character string identifying the context of the error
(e.g., "parameters", "model", "transform", or "generate").}
}
\value{
The result of evaluating the \code{expr}. If an error occurs, it throws
a formatted [stop()] message.
}
\description{
This internal helper function wraps an R expression in a [tryCatch()] block to
capture cryptic error messages generated by the RTMB automatic differentiation
engine or C++ backend, translating them into descriptive hints.
}
\details{
It uses regular expressions to categorize common RTMB failure modes, such as:
\itemize{
  \item **Missing Objects/Functions**: Detects if a variable or a specific distribution
  function (e.g., `normal_lpdf`) is missing from the environment.
  \item **Index Errors**: Identifies subscript out of bounds errors.
  \item **AD Type Destruction**: Catches the "lost class attribute" error, often caused
  by incorrect initialization of vectors (e.g., using `numeric(N)` and partial assignment
  inside loops).
  \item **Matrix Dimension Mismatch**: Identifies non-conformable arguments in
  matrix multiplication.
}
}
\keyword{internal}
