changeset 23:ad4ba83d0a43 task

Merge with launchpad trunk.
author David Grundberg <individ@acc.umu.se>
date Mon, 17 Nov 2008 12:29:09 +0100
parents 1a26d85a01be (current diff) 84be5ee8cc44 (diff)
children 83dd1cc42f36
files ChangeLog
diffstat 2 files changed, 49 insertions(+), 10 deletions(-) [+]
line wrap: on
line diff
--- a/ChangeLog	Mon Nov 17 10:38:05 2008 +0100
+++ b/ChangeLog	Mon Nov 17 12:29:09 2008 +0100
@@ -1,9 +1,14 @@
--*- coding:utf-8 -*-
+2008-11-17  Håkan Fors Nilsson  <c03hfn@cs.umu.se>
 
-2008-11-10  Håkan Fors Nilsson  <c04hfn@cs.umu.se>
+	* octave_to_python.cc: Added functions octcell_to_pyobject and 
+	octmap_to_pyobject.
+	* python_to_octave.cc: Added functions pydict_to_octmap and 
+	pylist_to_cellarray.
 
-	* octave_to_python.cc: Added functions octcell_to_pyobject and octmap_to_pyobject.
-	* python_to_octave.cc: Added functions pydict_to_octmap and pylist_to_cellarray.
+2008-11-17  David Grundberg  <individ@acc.umu.se>
+
+	* pytave.cc: func_eval: Improved pytave.OctaveError messages, now
+	includes filename, function and line of offending m-file.
 
 2008-11-10  David Grundberg  <individ@acc.umu.se>
 
@@ -32,3 +37,8 @@
 
 	First launchpad.net check in.
 
+Local Variables:
+coding: utf-8
+fillcolumn: 72
+End:
+vim: set textwidth=72 noexpandtab :
--- a/pytave.cc	Mon Nov 17 10:38:05 2008 +0100
+++ b/pytave.cc	Mon Nov 17 12:29:09 2008 +0100
@@ -24,6 +24,7 @@
 
 #undef HAVE_STAT /* Both boost.python and octave define HAVE_STAT... */
 #include <octave/oct.h>
+#include <octave/oct-map.h>
 #include <octave/octave.h>
 #include <octave/ov.h>
 #include <octave/parse.h>
@@ -95,12 +96,40 @@
 //  1 general error
          int parse_status = 0;
          reset_error_handler();
-         octave_value_list tmp = eval_string("lasterror.message",
-                                             true, parse_status, 1);
-         if (!tmp.empty() && tmp(0).is_string())
-            throw octave_error_exception(tmp(0).string_value());
-         else
-            throw octave_error_exception("");
+         octave_value_list lasterror = eval_string("lasterror",
+                                                   true, parse_status, 1);
+         if (!lasterror.empty() && lasterror(0).is_map()) {
+            ostringstream exceptionmsg;
+            Octave_map map = lasterror(0).map_value();
+            string message = map.stringfield("message", "");
+            string identifier = map.stringfield("identifier", "");
+            Cell stackCell = map.contents("stack");
+
+            // Trim trailing new lines
+            message = message.substr(0, message.find_last_not_of("\r\n") + 1);
+
+            if (!stackCell.is_empty() && stackCell(0).is_map()) {
+               // The struct element is called "stack" but only contain
+               // info about the top frame.
+               Octave_map stack = stackCell(0).map_value();
+               string file = stack.stringfield("file", "d");
+               string name = stack.stringfield("name", "a");
+               int line = stack.intfield("line", 1);
+               int column = stack.intfield("column", 2);
+
+               exceptionmsg << file << ":" << line << ":" << column << ": ";
+               if (!name.empty())
+                  exceptionmsg << "in '" << name << "': ";
+            }
+
+            if (!identifier.empty()) {
+               exceptionmsg << "(identifier: " << identifier << ") ";
+            }
+            exceptionmsg << message;
+
+            throw octave_error_exception(exceptionmsg.str());
+         } else
+            throw octave_error_exception("No Octave error available");
       }
 
       if (nargout > 0) {