line numbers in error messages

11 views
Skip to first unread message

Ben Goodrich

unread,
Oct 16, 2012, 11:33:45 PM10/16/12
to stan...@googlegroups.com
I think Bob mentioned that it would be good to have exceptions and other errors associate themselves with the line number in the code.

Apparently, this is easy with the __FILE__ and __LINE__ preprocessor macros, both of which seem to be supported by g++ and clang++; see

http://gcc.gnu.org/onlinedocs/cpp/Standard-Predefined-Macros.html

or

goodrich@CYBERPOWERPC:/tmp$ cat test.cpp
#include<fstream>

int main() {
     fprintf (stderr, "Internal error: "
                      "look at "
                      "%s, line %d.\n",
              __FILE__, __LINE__);

    return 0;
}
goodrich@CYBERPOWERPC:/
tmp$ clang++ test.cpp
goodrich@CYBERPOWERPC
:/tmp$ ./a.out
Internal error: look at test.cpp, line 7.


Ben


Marcus Brubaker

unread,
Oct 16, 2012, 11:46:35 PM10/16/12
to stan...@googlegroups.com
This is nice for C++ error messages, but it won't help end users track down errors in their models without diving into the C++ which is what Bob and I had talked about a bit a while back.  There is actually a straightforward way to do it, provided we could get the model file line numbers and line contents in the right part of the output but that involves some parser magic that has yet to be sorted out.

Cheers,
Marcus


Ben


--
 
 

Bob Carpenter

unread,
Oct 17, 2012, 12:46:01 PM10/17/12
to stan...@googlegroups.com

On 10/16/12 11:46 PM, Marcus Brubaker wrote:
> This is nice for C++ error messages, but it won't help end users track down errors in their models without diving into
> the C++ which is what Bob and I had talked about a bit a while back. There is actually a straightforward way to do it,
> provided we could get the model file line numbers and line contents in the right part of the output but that involves
> some parser magic that has yet to be sorted out.

It's on my to-do list, but quickly getting pushed
down by other issues. I'm also in the middle of
adding upper/lower bound constraints to vectors,
row vectors, and matrices.

- Bob


Reply all
Reply to author
Forward
0 new messages