Bookmark and Share

Notice: On April 23, 2014, Statalist moved from an email list to a forum, based at statalist.org.


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

Re: st: Detecting a macro expansion error


From   Nick Cox <njcoxstata@gmail.com>
To   statalist@hsphsun2.harvard.edu
Subject   Re: st: Detecting a macro expansion error
Date   Sun, 1 Jan 2012 19:26:48 +0000

You could try testing whether the expression evaluates to an empty
string. The usefulness of that approach depends on whether an empty
string is acceptable on other grounds.

Nick

On Sun, Jan 1, 2012 at 7:04 PM, Matthew White <mwhite@poverty-action.org> wrote:

> Using Stata 11.2 SE, I'm writing a program that requires me to parse a
> string passed to the program. I want the program to exit if the string
> contains a macro expansion that results in an error. Currently, Stata
> displays an error about the macro expansion without exiting, and then
> continues to parse the string and run the program. Generally, I want
> to know how I can detect whether a command results in a macro
> expansion error. Here's an example of what I mean:
>
> . display "`='Hello world"
> invalid syntax
> Hello world
>
> Here, the macro expansion `=' results in an invalid syntax error, but
> -display- is still executed (after `=' evaluates to ""), and there's
> no return code (r(198) is not displayed). -capture- doesn't help:
>
> . capture display "`='Hello world"
> invalid syntax
>
> . display _rc
> 0
>
> Essentially what I'd like is something like -capture- that I can use
> to determine whether a command results in a macro expansion error. Any
> ideas?
>
*
*   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–2018 StataCorp LLC   |   Terms of use   |   Privacy   |   Contact us   |   Site index