Commit 93380edb0d9e3dda754c64e00a808dd9d660e781

Authored by knodlseder
1 parent bae9df75

add xml_invalid_parnum and xml_invalid_parnames exceptions

include/GException.hpp
... ... @@ -551,6 +551,16 @@ public:
551 551 xml_name_not_found(std::string origin, std::string type,
552 552 std::string message = "");
553 553 };
  554 + class xml_invalid_parnum : public GExceptionHandler {
  555 + public:
  556 + xml_invalid_parnum(std::string origin, GXmlElement xml,
  557 + std::string message = "");
  558 + };
  559 + class xml_invalid_parnames : public GExceptionHandler {
  560 + public:
  561 + xml_invalid_parnames(std::string origin, GXmlElement xml,
  562 + std::string message = "");
  563 + };
554 564  
555 565  
556 566 // Model exceptions
... ...
src/xml/GException_xml.cpp
1 1 /***************************************************************************
2 2 * GException_xml.cpp - XML exception handlers *
3 3 * ----------------------------------------------------------------------- *
4   - * copyright (C) 2010-2011 by Jurgen Knodlseder *
  4 + * copyright (C) 2010-2011 by Juergen Knoedlseder *
5 5 * ----------------------------------------------------------------------- *
6 6 * *
7 7 * This program is free software: you can redistribute it and/or modify *
... ... @@ -18,6 +18,11 @@
18 18 * along with this program. If not, see <http://www.gnu.org/licenses/>. *
19 19 * *
20 20 ***************************************************************************/
  21 +/**
  22 + * @file GException_xml.cpp
  23 + * @brief Implement exceptions for the XML module
  24 + * @author J. Knoedlseder
  25 + */
21 26  
22 27 /* __ Includes ___________________________________________________________ */
23 28 #ifdef HAVE_CONFIG_H
... ... @@ -45,8 +50,9 @@ GException::xml_syntax_error::xml_syntax_error(std::string origin,
45 50 m_message = "XML syntax error ("+message+")";
46 51  
47 52 // Set segment
48   - if (segment.length() > 0)
49   - m_message += " occured in "+segment;
  53 + if (segment.length() > 0) {
  54 + m_message += " occured in " + segment;
  55 + }
50 56  
51 57 // Return
52 58 return;
... ... @@ -84,7 +90,10 @@ GException::xml_bad_node_type::xml_bad_node_type(std::string origin,
84 90 {
85 91 // Set origin and message
86 92 m_origin = origin;
87   - m_message = "Invalid XML node type ("+type+"). "+message;
  93 + m_message = "Invalid XML node type ("+type+").";
  94 + if (message.length() > 0) {
  95 + m_message += " " + message;
  96 + }
88 97  
89 98 // Return
90 99 return;
... ... @@ -104,8 +113,59 @@ GException::xml_name_not_found::xml_name_not_found(std::string origin,
104 113 {
105 114 // Set origin and message
106 115 m_origin = origin;
107   - m_message = "XML element name \""+name+"\" not found. "+message;
  116 + m_message = "XML element name \""+name+"\" not found.";
  117 + if (message.length() > 0) {
  118 + m_message += " " + message;
  119 + }
108 120  
109 121 // Return
110 122 return;
111 123 }
  124 +
  125 +
  126 +/***********************************************************************//**
  127 + * @brief Invalid number of parameters in XML element
  128 + *
  129 + * @param[in] origin Method that throws the error.
  130 + * @param[in] xml XML element.
  131 + * @param[in] message Optional error message.
  132 + ***************************************************************************/
  133 +GException::xml_invalid_parnum::xml_invalid_parnum(std::string origin,
  134 + GXmlElement xml,
  135 + std::string message)
  136 +{
  137 + // Set origin and message
  138 + m_origin = origin;
  139 + m_message = "Invalid number of parameters found in XML element.";
  140 + if (message.length() > 0) {
  141 + m_message += " " + message;
  142 + }
  143 +
  144 + // Return
  145 + return;
  146 +}
  147 +
  148 +
  149 +/***********************************************************************//**
  150 + * @brief Invalid parameter names in XML element
  151 + *
  152 + * @param[in] origin Method that throws the error.
  153 + * @param[in] xml XML element.
  154 + * @param[in] message Optional error message.
  155 + ***************************************************************************/
  156 +GException::xml_invalid_parnames::xml_invalid_parnames(std::string origin,
  157 + GXmlElement xml,
  158 + std::string message)
  159 +{
  160 + // Set origin and message
  161 + m_origin = origin;
  162 + m_message = "Invalid parameter names found in XML element." ;
  163 + if (message.length() > 0) {
  164 + m_message += " " + message;
  165 + }
  166 +
  167 + // Return
  168 + return;
  169 +}
  170 +
  171 +
... ...