Commit 8fb35e5d29ea37821db984fb67b60a0955daaf7d

Authored by knodlseder
1 parent 6c43ceef

add cvs_bad_columns exception

include/GException.hpp
@@ -459,6 +459,15 @@ public: @@ -459,6 +459,15 @@ public:
459 std::string message = ""); 459 std::string message = "");
460 }; 460 };
461 461
  462 +
  463 + // GCvs exceptions
  464 + class cvs_bad_columns : public GExceptionHandler {
  465 + public:
  466 + cvs_bad_columns(std::string origin, std::string filename,
  467 + int rows, int cols, int elements,
  468 + std::string message = "");
  469 + };
  470 +
462 }; 471 };
463 472
464 #endif /* GEXCEPTION_HPP */ 473 #endif /* GEXCEPTION_HPP */
src/support/GException.cpp
@@ -50,6 +50,7 @@ GException::feature_not_implemented::feature_not_implemented(std::string origin, @@ -50,6 +50,7 @@ GException::feature_not_implemented::feature_not_implemented(std::string origin,
50 " https://sourceforge.net/projects/gammalib/," 50 " https://sourceforge.net/projects/gammalib/,"
51 " join this error message and provide a detailed" 51 " join this error message and provide a detailed"
52 " description of your needs."; 52 " description of your needs.";
  53 + return;
53 } 54 }
54 55
55 56
@@ -63,6 +64,7 @@ GException::bad_type::bad_type(std::string origin, std::string message) @@ -63,6 +64,7 @@ GException::bad_type::bad_type(std::string origin, std::string message)
63 { 64 {
64 m_origin = origin; 65 m_origin = origin;
65 m_message = "Invalud type conversion. " + message; 66 m_message = "Invalud type conversion. " + message;
  67 + return;
66 } 68 }
67 69
68 70
@@ -76,6 +78,7 @@ GException::mem_alloc::mem_alloc(std::string origin, unsigned num) @@ -76,6 +78,7 @@ GException::mem_alloc::mem_alloc(std::string origin, unsigned num)
76 { 78 {
77 m_origin = origin; 79 m_origin = origin;
78 m_message = "Memory allocation error (" + str((int)num) + " elements)"; 80 m_message = "Memory allocation error (" + str((int)num) + " elements)";
  81 + return;
79 } 82 }
80 83
81 84
@@ -89,6 +92,7 @@ GException::not_enough_nodes::not_enough_nodes(std::string origin, int num) @@ -89,6 +92,7 @@ GException::not_enough_nodes::not_enough_nodes(std::string origin, int num)
89 { 92 {
90 m_origin = origin; 93 m_origin = origin;
91 m_message = "Not enough nodes in node array (" + str(num) + " nodes)."; 94 m_message = "Not enough nodes in node array (" + str(num) + " nodes).";
  95 + return;
92 } 96 }
93 97
94 98
@@ -102,6 +106,7 @@ GException::file_not_found::file_not_found(std::string origin, std::string filen @@ -102,6 +106,7 @@ GException::file_not_found::file_not_found(std::string origin, std::string filen
102 { 106 {
103 m_origin = origin; 107 m_origin = origin;
104 m_message = "File \"" + filename +"\" not found."; 108 m_message = "File \"" + filename +"\" not found.";
  109 + return;
105 } 110 }
106 111
107 112
@@ -115,4 +120,30 @@ GException::file_open_error::file_open_error(std::string origin, std::string fil @@ -115,4 +120,30 @@ GException::file_open_error::file_open_error(std::string origin, std::string fil
115 { 120 {
116 m_origin = origin; 121 m_origin = origin;
117 m_message = "Unable to open file \"" + filename +"\""; 122 m_message = "Unable to open file \"" + filename +"\"";
  123 + return;
  124 +}
  125 +
  126 +
  127 +/***********************************************************************//**
  128 + * @brief Bad CSV columns encountered
  129 + *
  130 + * @param[in] origin Name of method that has thrown the exception.
  131 + * @param[in] filename Filename.
  132 + * @param[in] row CSV file row.
  133 + * @param[in] cols Expected number of columns.
  134 + * @param[in] elements Found number of columns.
  135 + * @param[in] message Optional message.
  136 + ***************************************************************************/
  137 +GException::cvs_bad_columns::cvs_bad_columns(std::string origin,
  138 + std::string filename,
  139 + int row,
  140 + int cols,
  141 + int elements,
  142 + std::string message)
  143 +{
  144 + m_origin = origin;
  145 + m_message = "Inconsistent number of columns found in row "+str(row)+
  146 + " of file \""+filename+"\" ("+str(cols)+" expected, "+
  147 + str(elements)+" encountered). "+message;
  148 + return;
118 } 149 }