Statalist


[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: st: Custom error messages


From   Stas Kolenikov <skolenik@gmail.com>
To   statalist@hsphsun2.harvard.edu
Subject   Re: st: Custom error messages
Date   Tue, 24 Feb 2009 08:51:45 -0600

To expand further:

capture whatever
local rc = _rc
if `rc' {
   * may be some branching depending on the value of `rc'
   di "{err}Custom error message"
   exit `rc'
}

On 2/24/09, Nick Cox <n.j.cox@durham.ac.uk> wrote:
> To expand on this slightly:
>
>  Setting aside the implementation details, which are not of concern,
>  -error- is best thought of as a wrapper for -display as err- with some
>  generic message followed by -exit- and a non-zero return code.
>
>  Thus, if you want a different error message, or (less commonly) you want
>  a different or specific return code, you should fall back on -display-
>  followed by -exit-. It's certainly good style to add the return code.
>
>  Nick
>  n.j.cox@durham.ac.uk
>
>  Roger Harbord
>
>
>  On Tue, Feb 24, 2009 at 1:52 AM, Brian Karfunkel <bkarfunkel@gmail.com>
>  wrote:
>  >
>
> > Does anyone know how to output custom error messages? By this I mean
>  > either or both of:
>  >
>  > a) inserting my own strings into the "_______"s listed in error files.
>  > So, while "confirm variable foo" produces "variable foo not found;
>  > r(111)", I want to be able to have a command throw an error 111 with a
>  > message like "index variable not found".
>  <snip>
>
>  display as error "index variable not found"
>  exit 111
>
>
> *
>  *   For searches and help try:
>  *   http://www.stata.com/help.cgi?search
>  *   http://www.stata.com/support/statalist/faq
>  *   http://www.ats.ucla.edu/stat/stata/
>


-- 
Stas Kolenikov, also found at http://stas.kolenikov.name
Small print: I use this email account for mailing lists only.
*
*   For searches and help try:
*   http://www.stata.com/help.cgi?search
*   http://www.stata.com/support/statalist/faq
*   http://www.ats.ucla.edu/stat/stata/



© Copyright 1996–2014 StataCorp LP   |   Terms of use   |   Privacy   |   Contact us   |   What's new   |   Site index