Browse Source

TypeError, ValueError

David Rose 17 years ago
parent
commit
75c51589e8
1 changed files with 8 additions and 1 deletions
  1. 8 1
      direct/src/dcparser/dcField.cxx

+ 8 - 1
direct/src/dcparser/dcField.cxx

@@ -271,6 +271,7 @@ pack_args(DCPacker &packer, PyObject *sequence) const {
 
 
   if (!Notify::ptr()->has_assert_failed()) {
   if (!Notify::ptr()->has_assert_failed()) {
     ostringstream strm;
     ostringstream strm;
+    PyObject *exc_type = PyExc_StandardError;
 
 
     if (as_parameter() != (DCParameter *)NULL) {
     if (as_parameter() != (DCParameter *)NULL) {
       // If it's a parameter-type field, the value may or may not be a
       // If it's a parameter-type field, the value may or may not be a
@@ -281,9 +282,11 @@ pack_args(DCPacker &packer, PyObject *sequence) const {
       if (packer.had_pack_error()) {
       if (packer.had_pack_error()) {
         strm << "Incorrect arguments to field: " << get_name()
         strm << "Incorrect arguments to field: " << get_name()
              << " = " << PyString_AsString(str);
              << " = " << PyString_AsString(str);
+        exc_type = PyExc_TypeError;
       } else {
       } else {
         strm << "Value out of range on field: " << get_name()
         strm << "Value out of range on field: " << get_name()
              << " = " << PyString_AsString(str);
              << " = " << PyString_AsString(str);
+        exc_type = PyExc_ValueError;
       }
       }
       Py_DECREF(str);
       Py_DECREF(str);
 
 
@@ -297,6 +300,7 @@ pack_args(DCPacker &packer, PyObject *sequence) const {
 
 
         strm << "Value for " << get_name() << " not a sequence: " \
         strm << "Value for " << get_name() << " not a sequence: " \
              << PyString_AsString(str);
              << PyString_AsString(str);
+        exc_type = PyExc_TypeError;
         Py_DECREF(str);
         Py_DECREF(str);
 
 
       } else {
       } else {
@@ -305,9 +309,11 @@ pack_args(DCPacker &packer, PyObject *sequence) const {
         if (packer.had_pack_error()) {
         if (packer.had_pack_error()) {
           strm << "Incorrect arguments to field: " << get_name()
           strm << "Incorrect arguments to field: " << get_name()
                << PyString_AsString(str);
                << PyString_AsString(str);
+          exc_type = PyExc_TypeError;
         } else {
         } else {
           strm << "Value out of range on field: " << get_name()
           strm << "Value out of range on field: " << get_name()
                << PyString_AsString(str);
                << PyString_AsString(str);
+          exc_type = PyExc_ValueError;
         }
         }
         
         
         Py_DECREF(str);
         Py_DECREF(str);
@@ -315,7 +321,8 @@ pack_args(DCPacker &packer, PyObject *sequence) const {
       }
       }
     }
     }
 
 
-    nassert_raise(strm.str());
+    string message = strm.str();
+    PyErr_SetString(exc_type, message.c_str());
   }
   }
   return false;
   return false;
 }
 }