Mercurial > pytave
comparison pytave.cc @ 18:7a5fbc15fc6e error-msgs
Improved error messages from Octave.
author | David Grundberg <c04dgg@cs.umu.se> |
---|---|
date | Mon, 17 Nov 2008 12:10:04 +0100 |
parents | 56254a2e18e3 |
children | 5641245dd9d2 |
comparison
equal
deleted
inserted
replaced
17:1a2c103d1789 | 18:7a5fbc15fc6e |
---|---|
22 #include <boost/python.hpp> | 22 #include <boost/python.hpp> |
23 #include <boost/python/numeric.hpp> | 23 #include <boost/python/numeric.hpp> |
24 | 24 |
25 #undef HAVE_STAT /* Both boost.python and octave define HAVE_STAT... */ | 25 #undef HAVE_STAT /* Both boost.python and octave define HAVE_STAT... */ |
26 #include <octave/oct.h> | 26 #include <octave/oct.h> |
27 #include <octave/oct-map.h> | |
27 #include <octave/octave.h> | 28 #include <octave/octave.h> |
28 #include <octave/ov.h> | 29 #include <octave/ov.h> |
29 #include <octave/parse.h> | 30 #include <octave/parse.h> |
30 | 31 |
31 #include <iostream> | 32 #include <iostream> |
93 // -2 error without traceback | 94 // -2 error without traceback |
94 // -1 traceback | 95 // -1 traceback |
95 // 1 general error | 96 // 1 general error |
96 int parse_status = 0; | 97 int parse_status = 0; |
97 reset_error_handler(); | 98 reset_error_handler(); |
98 octave_value_list tmp = eval_string("lasterror.message", | 99 octave_value_list lasterror = eval_string("lasterror", |
99 true, parse_status, 1); | 100 true, parse_status, 1); |
100 if (!tmp.empty() && tmp(0).is_string()) | 101 if (!lasterror.empty() && lasterror(0).is_map()) { |
101 throw octave_error_exception(tmp(0).string_value()); | 102 ostringstream exceptionmsg; |
102 else | 103 Octave_map map = lasterror(0).map_value(); |
103 throw octave_error_exception(""); | 104 string message = map.stringfield("message", ""); |
105 string identifier = map.stringfield("identifier", ""); | |
106 Cell stackCell = map.contents("stack"); | |
107 | |
108 // Trim trailing new lines | |
109 message = message.substr(0, message.find_last_not_of("\r\n") + 1); | |
110 | |
111 if (!stackCell.is_empty() && stackCell(0).is_map()) { | |
112 // The struct element is called "stack" but only contain | |
113 // info about the top frame. | |
114 Octave_map stack = stackCell(0).map_value(); | |
115 string file = stack.stringfield("file", "d"); | |
116 string name = stack.stringfield("name", "a"); | |
117 int line = stack.intfield("line", 1); | |
118 int column = stack.intfield("column", 2); | |
119 | |
120 exceptionmsg << file << ":" << line << ":" << column << ": "; | |
121 if (!name.empty()) | |
122 exceptionmsg << "in '" << name << "': "; | |
123 } | |
124 | |
125 if (!identifier.empty()) { | |
126 exceptionmsg << "(identifier: " << identifier << ") "; | |
127 } | |
128 exceptionmsg << message; | |
129 | |
130 throw octave_error_exception(exceptionmsg.str()); | |
131 } else | |
132 throw octave_error_exception("No Octave error available"); | |
104 } | 133 } |
105 | 134 |
106 if (nargout > 0) { | 135 if (nargout > 0) { |
107 boost::python::tuple pytuple; | 136 boost::python::tuple pytuple; |
108 octlist_to_pytuple(pytuple, retval); | 137 octlist_to_pytuple(pytuple, retval); |