lmi-commits
[Top][All Lists]
Advanced

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

[lmi-commits] [lmi] master 987adcc 06/10: Get sequence parser diagnostic


From: Greg Chicares
Subject: [lmi-commits] [lmi] master 987adcc 06/10: Get sequence parser diagnostics from exception, not function
Date: Mon, 6 Feb 2017 04:10:56 +0000 (UTC)

branch: master
commit 987adcc3cb6aac1b5405ca7d41cc500c7a392fe9
Author: Gregory W. Chicares <address@hidden>
Commit: Gregory W. Chicares <address@hidden>

    Get sequence parser diagnostics from exception, not function
---
 input_sequence_entry.cpp |   80 ++++++++++++++++++++++++++--------------------
 1 file changed, 45 insertions(+), 35 deletions(-)

diff --git a/input_sequence_entry.cpp b/input_sequence_entry.cpp
index 8ee719e..1c17374 100644
--- a/input_sequence_entry.cpp
+++ b/input_sequence_entry.cpp
@@ -50,6 +50,7 @@
 #include <wx/valtext.h>
 
 #include <algorithm>                    // std::copy()
+#include <exception>
 #include <iterator>                     // std::back_inserter()
 #include <map>
 #include <vector>
@@ -1208,24 +1209,32 @@ wxString InputSequenceEditor::get_diagnostics_message()
 
     // Diagnose unanticipated input errors by invoking the parser;
     // return the first line of its diagnostics as an error message.
-    InputSequence const sequence
-        (sequence_string()
-        ,input_.years_to_maturity()
-        ,input_.issue_age        ()
-        ,input_.retirement_age   ()
-        ,input_.inforce_year     ()
-        ,input_.effective_year   ()
-        ,keywords_
-        ,keywords_only_
-        ,default_keyword_
-        );
-    std::string parser_diagnostics(sequence.formatted_diagnostics());
-    std::string::size_type z(parser_diagnostics.find('\n'));
-    if(std::string::npos != z)
+    try
+        {
+        InputSequence const sequence
+            (sequence_string()
+            ,input_.years_to_maturity()
+            ,input_.issue_age        ()
+            ,input_.retirement_age   ()
+            ,input_.inforce_year     ()
+            ,input_.effective_year   ()
+            ,keywords_
+            ,keywords_only_
+            ,default_keyword_
+            );
+        }
+    catch(std::exception const& e)
         {
-        parser_diagnostics.erase(z);
+        std::string parser_diagnostics(e.what());
+        std::string::size_type z(parser_diagnostics.find('\n'));
+        if(std::string::npos != z)
+            {
+            parser_diagnostics.erase(z);
+            }
+        return wxString(parser_diagnostics.c_str());
         }
-    return wxString(parser_diagnostics.c_str());
+
+    return wxString();
 }
 
 void InputSequenceEditor::UponValueChange(wxCommandEvent&)
@@ -1552,26 +1561,29 @@ void InputSequenceEntry::DoOpenEditor()
     LMI_ASSERT(!(keywords_only && keywords.empty()));
     editor.set_keywords(keywords, keywords_only, ds.default_keyword());
 
-    InputSequence sequence
-        (sequence_string
-        ,in.years_to_maturity()
-        ,in.issue_age        ()
-        ,in.retirement_age   ()
-        ,in.inforce_year     ()
-        ,in.effective_year   ()
-        ,keywords
-        ,keywords_only
-        ,ds.default_keyword()
-        );
-
-    std::string parser_diagnostics(sequence.formatted_diagnostics());
-    std::string::size_type z(parser_diagnostics.find('\n'));
-    if(std::string::npos != z)
+    try
         {
-        parser_diagnostics.erase(z);
+        InputSequence sequence
+            (sequence_string
+            ,in.years_to_maturity()
+            ,in.issue_age        ()
+            ,in.retirement_age   ()
+            ,in.inforce_year     ()
+            ,in.effective_year   ()
+            ,keywords
+            ,keywords_only
+            ,ds.default_keyword()
+            );
+        editor.sequence(sequence);
         }
-    if(!parser_diagnostics.empty())
+    catch(std::exception const& e)
         {
+        std::string parser_diagnostics(e.what());
+        std::string::size_type z(parser_diagnostics.find('\n'));
+        if(std::string::npos != z)
+            {
+            parser_diagnostics.erase(z);
+            }
         warning()
             << "The sequence is invalid and cannot be edited visually.\n"
             << parser_diagnostics
@@ -1580,8 +1592,6 @@ void InputSequenceEntry::DoOpenEditor()
         return;
         }
 
-    editor.sequence(sequence);
-
     editor.associate_text_ctrl(text_);
     editor.CentreOnParent();
 



reply via email to

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