lmi-commits
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[lmi-commits] [lmi] master de67a28 5/8: Improve an error message


From: Greg Chicares
Subject: [lmi-commits] [lmi] master de67a28 5/8: Improve an error message
Date: Sat, 20 Mar 2021 09:55:30 -0400 (EDT)

branch: master
commit de67a28b2623ee429f9dfa34b1c0ee62e1429b4c
Author: Gregory W. Chicares <gchicares@sbcglobal.net>
Commit: Gregory W. Chicares <gchicares@sbcglobal.net>

    Improve an error message
    
    State the arguments' lengths instead of just saying that they're
    nonconformable.
    
    Incidentally removed an unused parameter name.
---
 et_vector_test.cpp             |  3 ++-
 tools/pete-2.1.1/et_vector.hpp | 11 +++++++++--
 2 files changed, 11 insertions(+), 3 deletions(-)

diff --git a/et_vector_test.cpp b/et_vector_test.cpp
index 4e67020..3050703 100644
--- a/et_vector_test.cpp
+++ b/et_vector_test.cpp
@@ -50,7 +50,8 @@ int test_main(int, char*[])
     {
     std::vector<double> v0 = {0.0, 1.25, 2.5};
     std::vector<double> v1 = {0.0, 1.25, 2.5, 3.75};
-    LMI_TEST_THROW(v0 *= v1, std::runtime_error, "");
+    char const* s {"Nonconformable lengths: 3 lhs vs. 4 rhs."};
+    LMI_TEST_THROW(v0 *= v1, std::runtime_error, s);
     }
 
     // Test peteCast().
diff --git a/tools/pete-2.1.1/et_vector.hpp b/tools/pete-2.1.1/et_vector.hpp
index 3bb6f05..88147a5 100644
--- a/tools/pete-2.1.1/et_vector.hpp
+++ b/tools/pete-2.1.1/et_vector.hpp
@@ -56,6 +56,7 @@
 
 #include "PETE/PETE.h"
 
+#include <sstream>
 #include <stdexcept>
 #include <vector>
 
@@ -148,7 +149,7 @@ template<typename T>
 struct LeafFunctor<T, LengthLeaf>
 {
     typedef int Type_t;
-    static Type_t apply(T const& a, LengthLeaf const&)
+    static Type_t apply(T const&, LengthLeaf const&)
         {return 0;}
 };
 
@@ -182,7 +183,13 @@ inline void evaluate(std::vector<T>& t, Op const& op, 
Expression<U> const& u)
 {
     if(!forEach(u, SizeLeaf(lmi::ssize(t)), AndCombine()))
         {
-        throw std::runtime_error("Error: LHS and RHS don't conform.");
+        std::ostringstream oss;
+        oss
+            << "Nonconformable lengths: "
+            << lmi::ssize(t) << " lhs vs. "
+            << Rho(u) << " rhs."
+            ;
+        throw std::runtime_error(oss.str());
         }
 
     for(int i = 0; i < lmi::ssize(t); ++i)



reply via email to

[Prev in Thread] Current Thread [Next in Thread]