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]

st: Detecting a macro expansion error


From   Matthew White <[email protected]>
To   [email protected]
Subject   st: Detecting a macro expansion error
Date   Sun, 1 Jan 2012 14:04:04 -0500

Hi all,

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?

Thank you,
Matt

-- 
Matthew White
Data Coordinator
Innovations for Poverty Action
101 Whitney Avenue, New Haven, CT 06510 USA
+1 434-305-9861
www.poverty-action.org
*
*   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