Commit baa160452798211bac6835581721516e78401d19
1 parent
748eec87
Pass all arguments as const references for application module exceptions.
It is recommended to pass all arguments to exceptions by reference to avoid memory allocation during exception throwing.
Showing
2 changed files
with
103 additions
and
61 deletions
include/GException.hpp
| ... | ... | @@ -423,55 +423,55 @@ public: |
| 423 | 423 | // Application exceptions |
| 424 | 424 | class app_error : public GExceptionHandler { |
| 425 | 425 | public: |
| 426 | - app_error(std::string origin, | |
| 427 | - std::string message = ""); | |
| 426 | + app_error(const std::string& origin, | |
| 427 | + const std::string& message = ""); | |
| 428 | 428 | }; |
| 429 | 429 | class par_file_not_found : public GExceptionHandler { |
| 430 | 430 | public: |
| 431 | - par_file_not_found(std::string origin, | |
| 432 | - std::string filename, | |
| 433 | - std::string message = ""); | |
| 431 | + par_file_not_found(const std::string& origin, | |
| 432 | + const std::string& filename, | |
| 433 | + const std::string& message = ""); | |
| 434 | 434 | }; |
| 435 | 435 | class par_file_open_error : public GExceptionHandler { |
| 436 | 436 | public: |
| 437 | - par_file_open_error(std::string origin, | |
| 438 | - std::string filename, | |
| 439 | - std::string message = ""); | |
| 437 | + par_file_open_error(const std::string& origin, | |
| 438 | + const std::string& filename, | |
| 439 | + const std::string& message = ""); | |
| 440 | 440 | }; |
| 441 | 441 | class home_not_found : public GExceptionHandler { |
| 442 | 442 | public: |
| 443 | - home_not_found(std::string origin, | |
| 444 | - std::string message = ""); | |
| 443 | + home_not_found(const std::string& origin, | |
| 444 | + const std::string& message = ""); | |
| 445 | 445 | }; |
| 446 | 446 | class could_not_create_pfiles : public GExceptionHandler { |
| 447 | 447 | public: |
| 448 | - could_not_create_pfiles(std::string origin, | |
| 449 | - std::string home, | |
| 450 | - std::string message = ""); | |
| 448 | + could_not_create_pfiles(const std::string& origin, | |
| 449 | + const std::string& home, | |
| 450 | + const std::string& message = ""); | |
| 451 | 451 | }; |
| 452 | 452 | class pfiles_not_accessible : public GExceptionHandler { |
| 453 | 453 | public: |
| 454 | - pfiles_not_accessible(std::string origin, | |
| 455 | - std::string home, | |
| 456 | - std::string message = ""); | |
| 454 | + pfiles_not_accessible(const std::string& origin, | |
| 455 | + const std::string& home, | |
| 456 | + const std::string& message = ""); | |
| 457 | 457 | }; |
| 458 | 458 | class par_file_syntax_error : public GExceptionHandler { |
| 459 | 459 | public: |
| 460 | - par_file_syntax_error(std::string origin, | |
| 461 | - std::string home, | |
| 462 | - std::string message = ""); | |
| 460 | + par_file_syntax_error(const std::string& origin, | |
| 461 | + const std::string& home, | |
| 462 | + const std::string& message = ""); | |
| 463 | 463 | }; |
| 464 | 464 | class par_error : public GExceptionHandler { |
| 465 | 465 | public: |
| 466 | - par_error(std::string origin, | |
| 467 | - std::string name, | |
| 468 | - std::string message = ""); | |
| 466 | + par_error(const std::string& origin, | |
| 467 | + const std::string& name, | |
| 468 | + const std::string& message = ""); | |
| 469 | 469 | }; |
| 470 | 470 | class bad_cmdline_argument : public GExceptionHandler { |
| 471 | 471 | public: |
| 472 | - bad_cmdline_argument(std::string origin, | |
| 473 | - std::string arg, | |
| 474 | - std::string message = ""); | |
| 472 | + bad_cmdline_argument(const std::string& origin, | |
| 473 | + const std::string& arg, | |
| 474 | + const std::string& message = ""); | |
| 475 | 475 | }; |
| 476 | 476 | |
| 477 | 477 | ... | ... |
src/app/GException_app.cpp
| 1 | 1 | /*************************************************************************** |
| 2 | 2 | * GException_app.cpp - Application exception handlers * |
| 3 | 3 | * ----------------------------------------------------------------------- * |
| 4 | - * copyright (C) 2010-2011 by Jurgen Knodlseder * | |
| 4 | + * copyright (C) 2010-2012 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_app.hpp | |
| 23 | + * @brief Application exception handler interface definiton | |
| 24 | + * @author Juergen Knoedlseder | |
| 25 | + */ | |
| 21 | 26 | |
| 22 | 27 | /* __ Includes ___________________________________________________________ */ |
| 23 | 28 | #ifdef HAVE_CONFIG_H |
| ... | ... | @@ -33,7 +38,8 @@ |
| 33 | 38 | * @param[in] origin Method that throws the error. |
| 34 | 39 | * @param[in] message Optional error message. |
| 35 | 40 | ***************************************************************************/ |
| 36 | -GException::app_error::app_error(std::string origin, std::string message) | |
| 41 | +GException::app_error::app_error(const std::string& origin, | |
| 42 | + const std::string& message) | |
| 37 | 43 | { |
| 38 | 44 | // Set origin |
| 39 | 45 | m_origin = origin; |
| ... | ... | @@ -53,15 +59,20 @@ GException::app_error::app_error(std::string origin, std::string message) |
| 53 | 59 | * @param[in] filename Filename that was not found. |
| 54 | 60 | * @param[in] message Optional error message. |
| 55 | 61 | ***************************************************************************/ |
| 56 | -GException::par_file_not_found::par_file_not_found(std::string origin, | |
| 57 | - std::string filename, | |
| 58 | - std::string message) | |
| 62 | +GException::par_file_not_found::par_file_not_found(const std::string& origin, | |
| 63 | + const std::string& filename, | |
| 64 | + const std::string& message) | |
| 59 | 65 | { |
| 60 | 66 | // Set origin and message |
| 61 | 67 | m_origin = origin; |
| 62 | - m_message = "Parameter file '"+filename+"' not found. " | |
| 68 | + m_message = "Parameter file \""+filename+"\" not found. " | |
| 63 | 69 | "Make sure that PFILES environment variable is set " |
| 64 | - "correctly. " + message; | |
| 70 | + "correctly."; | |
| 71 | + | |
| 72 | + // Add optional error message | |
| 73 | + if (message.length() > 0) { | |
| 74 | + m_message += " " + message; | |
| 75 | + } | |
| 65 | 76 | |
| 66 | 77 | // Return |
| 67 | 78 | return; |
| ... | ... | @@ -75,13 +86,18 @@ GException::par_file_not_found::par_file_not_found(std::string origin, |
| 75 | 86 | * @param[in] filename Filename that could not be opened. |
| 76 | 87 | * @param[in] message Optional error message. |
| 77 | 88 | ***************************************************************************/ |
| 78 | -GException::par_file_open_error::par_file_open_error(std::string origin, | |
| 79 | - std::string filename, | |
| 80 | - std::string message) | |
| 89 | +GException::par_file_open_error::par_file_open_error(const std::string& origin, | |
| 90 | + const std::string& filename, | |
| 91 | + const std::string& message) | |
| 81 | 92 | { |
| 82 | 93 | // Set origin and message |
| 83 | 94 | m_origin = origin; |
| 84 | - m_message = "Unable to open parameter file '"+filename+"'. " + message; | |
| 95 | + m_message = "Unable to open parameter file \""+filename+"\"."; | |
| 96 | + | |
| 97 | + // Add optional error message | |
| 98 | + if (message.length() > 0) { | |
| 99 | + m_message += " " + message; | |
| 100 | + } | |
| 85 | 101 | |
| 86 | 102 | // Return |
| 87 | 103 | return; |
| ... | ... | @@ -94,12 +110,17 @@ GException::par_file_open_error::par_file_open_error(std::string origin, |
| 94 | 110 | * @param[in] origin Method that throws the error. |
| 95 | 111 | * @param[in] message Optional error message. |
| 96 | 112 | ***************************************************************************/ |
| 97 | -GException::home_not_found::home_not_found(std::string origin, | |
| 98 | - std::string message) | |
| 113 | +GException::home_not_found::home_not_found(const std::string& origin, | |
| 114 | + const std::string& message) | |
| 99 | 115 | { |
| 100 | 116 | // Set origin and message |
| 101 | 117 | m_origin = origin; |
| 102 | - m_message = "Unable to determine users home directory. " + message; | |
| 118 | + m_message = "Unable to determine users home directory."; | |
| 119 | + | |
| 120 | + // Add optional error message | |
| 121 | + if (message.length() > 0) { | |
| 122 | + m_message += " " + message; | |
| 123 | + } | |
| 103 | 124 | |
| 104 | 125 | // Return |
| 105 | 126 | return; |
| ... | ... | @@ -113,13 +134,18 @@ GException::home_not_found::home_not_found(std::string origin, |
| 113 | 134 | * @param[in] home Users home directory. |
| 114 | 135 | * @param[in] message Optional error message. |
| 115 | 136 | ***************************************************************************/ |
| 116 | -GException::could_not_create_pfiles::could_not_create_pfiles(std::string origin, | |
| 117 | - std::string home, | |
| 118 | - std::string message) | |
| 137 | +GException::could_not_create_pfiles::could_not_create_pfiles(const std::string& origin, | |
| 138 | + const std::string& home, | |
| 139 | + const std::string& message) | |
| 119 | 140 | { |
| 120 | 141 | // Set origin and message |
| 121 | 142 | m_origin = origin; |
| 122 | - m_message = "Unable to create '"+home+"'. " + message; | |
| 143 | + m_message = "Unable to create \""+home+"\"."; | |
| 144 | + | |
| 145 | + // Add optional error message | |
| 146 | + if (message.length() > 0) { | |
| 147 | + m_message += " " + message; | |
| 148 | + } | |
| 123 | 149 | |
| 124 | 150 | // Return |
| 125 | 151 | return; |
| ... | ... | @@ -133,14 +159,19 @@ GException::could_not_create_pfiles::could_not_create_pfiles(std::string origin, |
| 133 | 159 | * @param[in] home Users home directory. |
| 134 | 160 | * @param[in] message Optional error message. |
| 135 | 161 | ***************************************************************************/ |
| 136 | -GException::pfiles_not_accessible::pfiles_not_accessible(std::string origin, | |
| 137 | - std::string home, | |
| 138 | - std::string message) | |
| 162 | +GException::pfiles_not_accessible::pfiles_not_accessible(const std::string& origin, | |
| 163 | + const std::string& home, | |
| 164 | + const std::string& message) | |
| 139 | 165 | { |
| 140 | 166 | // Set origin and message |
| 141 | 167 | m_origin = origin; |
| 142 | - m_message = "Could not make '"+home+"' write accessible for " | |
| 143 | - "writing of the applications parameter file. " + message; | |
| 168 | + m_message = "Could not make \""+home+"\" write accessible for " | |
| 169 | + "writing of the applications parameter file."; | |
| 170 | + | |
| 171 | + // Add optional error message | |
| 172 | + if (message.length() > 0) { | |
| 173 | + m_message += " " + message; | |
| 174 | + } | |
| 144 | 175 | |
| 145 | 176 | // Return |
| 146 | 177 | return; |
| ... | ... | @@ -154,18 +185,20 @@ GException::pfiles_not_accessible::pfiles_not_accessible(std::string origin, |
| 154 | 185 | * @param[in] line Parameter file line in which syntax error occured. |
| 155 | 186 | * @param[in] message Optional error message. |
| 156 | 187 | ***************************************************************************/ |
| 157 | -GException::par_file_syntax_error::par_file_syntax_error(std::string origin, | |
| 158 | - std::string line, | |
| 159 | - std::string message) | |
| 188 | +GException::par_file_syntax_error::par_file_syntax_error(const std::string& origin, | |
| 189 | + const std::string& line, | |
| 190 | + const std::string& message) | |
| 160 | 191 | { |
| 161 | 192 | // Set origin and message |
| 162 | 193 | m_origin = origin; |
| 163 | - if (message.length() > 0) | |
| 194 | + if (message.length() > 0) { | |
| 164 | 195 | m_message = "Syntax error occured in the following line of the " |
| 165 | 196 | "parameter file ("+message+"): "+line; |
| 166 | - else | |
| 197 | + } | |
| 198 | + else { | |
| 167 | 199 | m_message = "Syntax error occured in the following line of the " |
| 168 | 200 | "parameter file: "+line; |
| 201 | + } | |
| 169 | 202 | |
| 170 | 203 | // Return |
| 171 | 204 | return; |
| ... | ... | @@ -179,14 +212,20 @@ GException::par_file_syntax_error::par_file_syntax_error(std::string origin, |
| 179 | 212 | * @param[in] name Parameter name. |
| 180 | 213 | * @param[in] message Optional error message. |
| 181 | 214 | ***************************************************************************/ |
| 182 | -GException::par_error::par_error(std::string origin, std::string name, | |
| 183 | - std::string message) | |
| 215 | +GException::par_error::par_error(const std::string& origin, | |
| 216 | + const std::string& name, | |
| 217 | + const std::string& message) | |
| 184 | 218 | { |
| 185 | 219 | // Set origin |
| 186 | 220 | m_origin = origin; |
| 187 | 221 | |
| 188 | 222 | // Set message |
| 189 | - m_message = "Parameter \""+name+"\": " + message; | |
| 223 | + m_message = "Parameter \""+name+"\""; | |
| 224 | + | |
| 225 | + // Add optional error message | |
| 226 | + if (message.length() > 0) { | |
| 227 | + m_message += ": " + message; | |
| 228 | + } | |
| 190 | 229 | |
| 191 | 230 | // Return |
| 192 | 231 | return; |
| ... | ... | @@ -200,18 +239,21 @@ GException::par_error::par_error(std::string origin, std::string name, |
| 200 | 239 | * @param[in] arg Command line argument. |
| 201 | 240 | * @param[in] message Optional error message. |
| 202 | 241 | ***************************************************************************/ |
| 203 | -GException::bad_cmdline_argument::bad_cmdline_argument(std::string origin, | |
| 204 | - std::string arg, | |
| 205 | - std::string message) | |
| 242 | +GException::bad_cmdline_argument::bad_cmdline_argument(const std::string& origin, | |
| 243 | + const std::string& arg, | |
| 244 | + const std::string& message) | |
| 206 | 245 | { |
| 207 | 246 | // Set origin and message |
| 208 | 247 | m_origin = origin; |
| 209 | - if (message.length() > 0) | |
| 248 | + if (message.length() > 0) { | |
| 210 | 249 | m_message = "Invalid command line parameter encountered ("+message+ |
| 211 | 250 | "): "+arg; |
| 212 | - else | |
| 251 | + } | |
| 252 | + else { | |
| 213 | 253 | m_message = "Invalid command line parameter encountered: "+arg; |
| 254 | + } | |
| 214 | 255 | |
| 215 | 256 | // Return |
| 216 | 257 | return; |
| 217 | 258 | } |
| 259 | + | ... | ... |