Commit d97403cecd0a78fa99ce4eadf8801267e18c53ef

Authored by Jürgen Knödlseder
1 parent e7312f15

Replace specific by generic exceptions in app module (#35)

include/GException.hpp
1 1 /***************************************************************************
2 2 * GException.hpp - Exception handler *
3 3 * ----------------------------------------------------------------------- *
4   - * copyright (C) 2006-2017 by Juergen Knoedlseder *
  4 + * copyright (C) 2006-2021cby Juergen Knoedlseder *
5 5 * ----------------------------------------------------------------------- *
6 6 * *
7 7 * This program is free software: you can redistribute it and/or modify *
... ... @@ -475,62 +475,6 @@ public:
475 475 wcs_invalid_phi_theta(std::string origin, int num, std::string message = "");
476 476 };
477 477  
478   -
479   - // Application exceptions
480   - class app_error : public GExceptionHandler {
481   - public:
482   - app_error(const std::string& origin,
483   - const std::string& message = "");
484   - };
485   - class par_file_not_found : public GExceptionHandler {
486   - public:
487   - par_file_not_found(const std::string& origin,
488   - const std::string& filename,
489   - const std::string& message = "");
490   - };
491   - class par_file_open_error : public GExceptionHandler {
492   - public:
493   - par_file_open_error(const std::string& origin,
494   - const std::string& filename,
495   - const std::string& message = "");
496   - };
497   - class home_not_found : public GExceptionHandler {
498   - public:
499   - home_not_found(const std::string& origin,
500   - const std::string& message = "");
501   - };
502   - class could_not_create_pfiles : public GExceptionHandler {
503   - public:
504   - could_not_create_pfiles(const std::string& origin,
505   - const std::string& home,
506   - const std::string& message = "");
507   - };
508   - class pfiles_not_accessible : public GExceptionHandler {
509   - public:
510   - pfiles_not_accessible(const std::string& origin,
511   - const std::string& home,
512   - const std::string& message = "");
513   - };
514   - class par_file_syntax_error : public GExceptionHandler {
515   - public:
516   - par_file_syntax_error(const std::string& origin,
517   - const std::string& home,
518   - const std::string& message = "");
519   - };
520   - class par_error : public GExceptionHandler {
521   - public:
522   - par_error(const std::string& origin,
523   - const std::string& name,
524   - const std::string& message = "");
525   - };
526   - class bad_cmdline_argument : public GExceptionHandler {
527   - public:
528   - bad_cmdline_argument(const std::string& origin,
529   - const std::string& arg,
530   - const std::string& message = "");
531   - };
532   -
533   -
534 478 // Observation exceptions
535 479 class no_response : public GExceptionHandler {
536 480 public:
... ...
src/app/GApplicationPar.cpp
1 1 /***************************************************************************
2 2 * GApplicationPar.cpp - Application parameter *
3 3 * ----------------------------------------------------------------------- *
4   - * copyright (C) 2010-2018 by Juergen Knoedlseder *
  4 + * copyright (C) 2010-2021 by Juergen Knoedlseder *
5 5 * ----------------------------------------------------------------------- *
6 6 * *
7 7 * This program is free software: you can redistribute it and/or modify *
... ... @@ -33,11 +33,11 @@
33 33 #include <readline/readline.h>
34 34 #endif
35 35 #include <climits> //!< Needed for declaration of LONG_MAX
36   -#include "GApplicationPar.hpp"
37   -#include "GTools.hpp"
38 36 #include "GException.hpp"
  37 +#include "GTools.hpp"
39 38 #include "GFilename.hpp"
40 39 #include "GTime.hpp"
  40 +#include "GApplicationPar.hpp"
41 41  
42 42 /* __ Method name definitions ____________________________________________ */
43 43 #define G_STRING_SET "GApplicationPar::string(std::string&)"
... ...
src/app/GApplicationPars.cpp
1 1 /***************************************************************************
2 2 * GApplicationPars.cpp - Application parameters *
3 3 * ----------------------------------------------------------------------- *
4   - * copyright (C) 2010-2020 by Juergen Knoedlseder *
  4 + * copyright (C) 2010-2021 by Juergen Knoedlseder *
5 5 * ----------------------------------------------------------------------- *
6 6 * *
7 7 * This program is free software: you can redistribute it and/or modify *
... ... @@ -35,8 +35,8 @@
35 35 #include <cstdlib> // std::getenv() function
36 36 #include <cstdio> // std::fopen(), etc. functions
37 37 #include <sstream>
38   -#include "GTools.hpp"
39 38 #include "GException.hpp"
  39 +#include "GTools.hpp"
40 40 #include "GFilename.hpp"
41 41 #include "GApplicationPars.hpp"
42 42  
... ... @@ -464,8 +464,6 @@ GApplicationPar&amp; GApplicationPars::insert(const int&amp; index, const GApplicationPa
464 464 *
465 465 * @exception GException::invalid_argument
466 466 * Parameter with specified name not found in container.
467   - * @exception GException::invalid_value
468   - * Name of parameter exists already in container.
469 467 *
470 468 * Inserts a parameter into the container before the parameter with the
471 469 * specified @p name.
... ... @@ -478,9 +476,9 @@ GApplicationPar&amp; GApplicationPars::insert(const std::string&amp; name,
478 476  
479 477 // Throw exception if parameter name was not found
480 478 if (index == -1) {
481   - std::string msg = "Parameter \""+name+"\" has not been found in"
482   - " parameter file.\n"
483   - "Please specify a valid parameter name.";
  479 + std::string msg = "Parameter \""+name+"\" has not been found in "
  480 + "parameter file. Please specify a valid parameter "
  481 + "name.";
484 482 throw GException::invalid_argument(G_INSERT2, msg);
485 483 }
486 484  
... ... @@ -544,9 +542,9 @@ void GApplicationPars::remove(const std::string&amp; name)
544 542  
545 543 // Throw exception if parameter name was not found
546 544 if (index == -1) {
547   - std::string msg = "Parameter \""+name+"\" has not been found in"
548   - " parameter file.\n"
549   - "Please specify a valid parameter name.";
  545 + std::string msg = "Parameter \""+name+"\" has not been found in "
  546 + "parameter file. Please specify a valid parameter "
  547 + "name.";
550 548 throw GException::invalid_argument(G_REMOVE2, msg);
551 549 }
552 550  
... ... @@ -563,6 +561,9 @@ void GApplicationPars::remove(const std::string&amp; name)
563 561 *
564 562 * @param[in] pars Parameter container.
565 563 *
  564 + * @exception GException::invalid_value
  565 + * Parameter with the same name exists already.
  566 + *
566 567 * Append parameter container to the container.
567 568 ***************************************************************************/
568 569 void GApplicationPars::extend(const GApplicationPars& pars)
... ... @@ -586,11 +587,10 @@ void GApplicationPars::extend(const GApplicationPars&amp; pars)
586 587 if (inx != -1) {
587 588 std::string msg =
588 589 "Attempt to append parameter with name \""+pars[i].name()+
589   - "\" to parameter container, but a parameter with the same name"
590   - " exists already at index "+gammalib::str(inx)+" in the"
591   - " container.\n"
592   - "Every parameter in the parameter container needs a unique"
593   - " name.";
  590 + "\" to parameter container, but a parameter with the same "
  591 + "name exists already at index "+gammalib::str(inx)+" in "
  592 + "the container. Every parameter in the parameter container "
  593 + "needs to have a unique name.";
594 594 throw GException::invalid_value(G_EXTEND, msg);
595 595 }
596 596  
... ... @@ -630,7 +630,7 @@ bool GApplicationPars::contains(const std::string&amp; name) const
630 630 *
631 631 * @param[in] filename Parameter filename.
632 632 *
633   - * @exception GException::par_file_not_found
  633 + * @exception GException::invalid_argument
634 634 * Parameter file not found.
635 635 *
636 636 * Loads all parameters from parameter file.
... ... @@ -676,7 +676,10 @@ void GApplicationPars::load(const GFilename&amp; filename)
676 676  
677 677 // If file path is empty then throw an exception
678 678 if (path.empty()) {
679   - throw GException::par_file_not_found(G_LOAD1, filename.url());
  679 + std::string msg = "Parameter file \""+filename.url()+"\" not "
  680 + "found. Please specify an existing parameter "
  681 + "file.";
  682 + throw GException::invalid_argument(G_LOAD1, msg);
680 683 }
681 684  
682 685 // Read parfile
... ... @@ -698,7 +701,7 @@ void GApplicationPars::load(const GFilename&amp; filename)
698 701 * @param[in] filename Parameter filename.
699 702 * @param[in] args Command line arguments.
700 703 *
701   - * @exception GException::bad_cmdline_argument
  704 + * @exception GException::invalid_argument
702 705 * Invalid command line argument encountered.
703 706 *
704 707 * Loads all parameters from parameter file. Parameters are overwritten by
... ... @@ -716,28 +719,38 @@ void GApplicationPars::load(const GFilename&amp; filename,
716 719 // Extract parameter name and value (empty values are permitted)
717 720 size_t pos = args[i].find("=");
718 721 if (pos == std::string::npos) {
719   - throw GException::bad_cmdline_argument(G_LOAD2, args[i],
720   - "no \"=\" specified");
  722 + std::string msg = "No \"=\" symbol found for command line "
  723 + "parameter \""+args[i]+"\". Please specify a "
  724 + "valid command line parameter of the form "
  725 + "\"name=value\".";
  726 + throw GException::invalid_argument(G_LOAD2, msg);
721 727 }
722 728 std::string name = args[i].substr(0, pos);
723 729 std::string value = args[i].substr(pos+1);
724 730 if (name.length() < 1) {
725   - throw GException::bad_cmdline_argument(G_LOAD2, args[i],
726   - "no parameter name before \"=\"");
  731 + std::string msg = "No parameter name found for before the \"=\" "
  732 + "symbol for command line parameter \""+args[i]+
  733 + "\". Please specify a valid command line "
  734 + "parameter of the form \"name=value\".";
  735 + throw GException::invalid_argument(G_LOAD2, msg);
727 736 }
728 737  
729 738 // Check if parameter exists
730 739 if (!contains(name)) {
731   - throw GException::bad_cmdline_argument(G_LOAD2, args[i],
732   - "invalid parameter name \""+name+"\"");
  740 + std::string msg = "No parameter with name \""+name+"\" found. "
  741 + "Please specify an existing command line "
  742 + "parameter.";
  743 + throw GException::invalid_argument(G_LOAD2, msg);
733 744 }
734 745  
735 746 // Assign value
736 747 try {
737 748 (*this)[name].value(value);
738 749 }
739   - catch (GException::par_error &e) {
740   - throw GException::bad_cmdline_argument(G_LOAD2, args[i]);
  750 + catch (GException::invalid_value &e) {
  751 + std::string msg = "Assignment of command line parameter \""+
  752 + args[i]+"\" failed.";
  753 + throw GException::invalid_argument(G_LOAD2, msg);
741 754 }
742 755  
743 756 // Set mode to hidden to prevent querying the parameter
... ... @@ -763,7 +776,7 @@ void GApplicationPars::load(const GFilename&amp; filename,
763 776 *
764 777 * @param[in] filename Parameter filename.
765 778 *
766   - * @exception GException::par_file_not_found
  779 + * @exception GException::file_error
767 780 * No valid directory to write the parameter file has been found.
768 781 ***************************************************************************/
769 782 void GApplicationPars::save(const GFilename& filename)
... ... @@ -771,7 +784,10 @@ void GApplicationPars::save(const GFilename&amp; filename)
771 784 // Get path to parameter file for output
772 785 std::string path = outpath(filename.url());
773 786 if (path.size() == 0) {
774   - throw GException::par_file_not_found(G_SAVE, filename.url());
  787 + std::string msg = "Parameter file \""+filename+"\" not found. Please "
  788 + "make sure that the PFILES environment variable is "
  789 + "set correctly.";
  790 + throw GException::file_error(G_LOAD2, msg);
775 791 }
776 792  
777 793 // Update parameter file
... ... @@ -815,8 +831,6 @@ void GApplicationPars::pickle(const std::vector&lt;std::string&gt;&amp; string)
815 831 int n_par = gammalib::toint(string[istring]);
816 832 int i_start = istring + 1;
817 833 int i_end = i_start + n_par;
818   - //std::vector<std::string> sub(string.begin()+i_start,
819   - // string.begin()+i_end);
820 834 GApplicationPar par;
821 835 par.pickle(std::vector<std::string>(string.begin()+i_start,
822 836 string.begin()+i_end));
... ... @@ -1174,11 +1188,9 @@ std::string GApplicationPars::syspfiles_path(const std::string&amp; filename) const
1174 1188 *
1175 1189 * @param[in] filename Parameter filename.
1176 1190 *
1177   - * @exception GException::home_not_found
  1191 + * @exception GException::runtime_error
1178 1192 * Unable to determine users home directory.
1179   - * @exception GException::could_not_create_pfiles
1180 1193 * Unable to create pfiles directory.
1181   - * @exception GException::pfiles_not_accessible
1182 1194 * Unable to make pfiles directory accessible to user.
1183 1195 *
1184 1196 * Searchs for first writable directory listed in PFILES environment
... ... @@ -1220,7 +1232,8 @@ std::string GApplicationPars::outpath(const std::string&amp; filename) const
1220 1232 gid_t gid = getegid();
1221 1233 struct passwd* pw = getpwuid(uid);
1222 1234 if (pw == NULL) {
1223   - throw GException::home_not_found(G_OUTPATH);
  1235 + std::string msg = "Unable to determine users home directory.";
  1236 + throw GException::runtime_error(G_OUTPATH, msg);
1224 1237 }
1225 1238  
1226 1239 // Set path
... ... @@ -1230,7 +1243,8 @@ std::string GApplicationPars::outpath(const std::string&amp; filename) const
1230 1243 if (access(path.c_str(), F_OK) != 0) {
1231 1244 if (mkdir(path.c_str(),
1232 1245 S_IRWXU | S_IRGRP | S_IXGRP | S_IROTH | S_IXOTH) != 0) {
1233   - throw GException::could_not_create_pfiles(G_OUTPATH, path);
  1246 + std::string msg = "Unable to create \""+path+"\".";
  1247 + throw GException::runtime_error(G_OUTPATH, msg);
1234 1248 }
1235 1249 }
1236 1250  
... ... @@ -1239,7 +1253,10 @@ std::string GApplicationPars::outpath(const std::string&amp; filename) const
1239 1253 if (chown(path.c_str(), uid, gid) != 0 ||
1240 1254 chmod(path.c_str(),
1241 1255 S_IRWXU | S_IRGRP | S_IXGRP | S_IROTH | S_IXOTH) != 0) {
1242   - throw GException::pfiles_not_accessible(G_OUTPATH, path);
  1256 + std::string msg = "Could not make \""+path+"\" write "
  1257 + "accessible for writing of the applications "
  1258 + "parameter file.";
  1259 + throw GException::runtime_error(G_OUTPATH, msg);
1243 1260 }
1244 1261 }
1245 1262  
... ... @@ -1258,7 +1275,7 @@ std::string GApplicationPars::outpath(const std::string&amp; filename) const
1258 1275 *
1259 1276 * @param[in] filename Parameter filename (absolut path).
1260 1277 *
1261   - * @exception GException::par_file_open_error
  1278 + * @exception GException::file_error
1262 1279 * Unable to open parameter file (read access requested).
1263 1280 *
1264 1281 * Read all lines of the parameter file. Each line is terminated by a newline
... ... @@ -1287,13 +1304,15 @@ void GApplicationPars::read(const std::string&amp; filename)
1287 1304 lock.l_pid = getpid(); // Current process ID
1288 1305 int fd;
1289 1306 if ((fd = open(filename.c_str(), O_RDONLY)) == -1) {
1290   - throw GException::par_file_open_error(G_READ, filename,
1291   - "Could not open file for locking.");
  1307 + std::string msg = "Could not open parameter file \""+filename+
  1308 + "\" for locking.";
  1309 + throw GException::file_error(G_READ, msg);
1292 1310 }
1293 1311 #if defined(G_CHECK_LOCK_PARFILE)
1294 1312 if (fcntl(fd, F_SETLKW, &lock) == -1) { // F_SETLKW: wait until unlocked
1295   - throw GException::par_file_open_error(G_READ, filename,
1296   - "Could not get a lock on the file.");
  1313 + std::string msg = "Could not get a lock on the parameter file \""+
  1314 + filename+"\".";
  1315 + throw GException::file_error(G_READ, msg);
1297 1316 }
1298 1317 #else
1299 1318 fcntl(fd, F_SETLKW, &lock);
... ... @@ -1303,7 +1322,9 @@ void GApplicationPars::read(const std::string&amp; filename)
1303 1322 // Open parameter file
1304 1323 FILE* fptr = fopen(filename.c_str(), "r");
1305 1324 if (fptr == NULL) {
1306   - throw GException::par_file_open_error(G_READ, filename);
  1325 + std::string msg = "Could not open the parameter file \""+
  1326 + filename+"\" for reading.";
  1327 + throw GException::file_error(G_READ, msg);
1307 1328 }
1308 1329  
1309 1330 // Read lines
... ... @@ -1320,8 +1341,9 @@ void GApplicationPars::read(const std::string&amp; filename)
1320 1341 lock.l_type = F_UNLCK;
1321 1342 #if defined(G_CHECK_LOCK_PARFILE)
1322 1343 if (fcntl(fd, F_SETLK, &lock) == -1) {
1323   - throw GException::par_file_open_error(G_READ, filename,
1324   - "Could not unlock the file.");
  1344 + std::string msg = "Could not unlock the parameter file \""+
  1345 + filename+"\".";
  1346 + throw GException::file_error(G_READ, msg);
1325 1347 }
1326 1348 #else
1327 1349 fcntl(fd, F_SETLK, &lock);
... ... @@ -1341,7 +1363,7 @@ void GApplicationPars::read(const std::string&amp; filename)
1341 1363 *
1342 1364 * @param[in] filename Parameter filename (absolut path).
1343 1365 *
1344   - * @exception GException::par_file_open_error
  1366 + * @exception GException::file_error
1345 1367 * Unable to open parameter file (write access requested).
1346 1368 *
1347 1369 * Writes all lines of the parameter file. The file will be locked to avoid
... ... @@ -1369,8 +1391,9 @@ void GApplicationPars::write(const std::string&amp; filename) const
1369 1391 if ((fd = open(filename.c_str(), O_WRONLY)) != -1) {
1370 1392 #if defined(G_CHECK_LOCK_PARFILE)
1371 1393 if (fcntl(fd, F_SETLKW, &lock) == -1) { // F_SETLKW: wait until unlocked
1372   - throw GException::par_file_open_error(G_WRITE, filename,
1373   - "Could not get a lock on the file.");
  1394 + std::string msg = "Could not get a lock on the parameter file \""+
  1395 + filename+"\".";
  1396 + throw GException::file_error(G_WRITE, msg);
1374 1397 }
1375 1398 #else
1376 1399 fcntl(fd, F_SETLKW, &lock);
... ... @@ -1381,7 +1404,9 @@ void GApplicationPars::write(const std::string&amp; filename) const
1381 1404 // Open parameter file.
1382 1405 FILE* fptr = fopen(filename.c_str(), "w");
1383 1406 if (fptr == NULL) {
1384   - throw GException::par_file_open_error(G_WRITE, filename);
  1407 + std::string msg = "Could not open the parameter file \""+
  1408 + filename+"\" for writing.";
  1409 + throw GException::file_error(G_WRITE, msg);
1385 1410 }
1386 1411  
1387 1412 // If file is not locked then lock it now.
... ... @@ -1391,8 +1416,9 @@ void GApplicationPars::write(const std::string&amp; filename) const
1391 1416 #if defined(G_CHECK_LOCK_PARFILE)
1392 1417 if (fcntl(fd, F_SETLKW, &lock) == -1) { // F_SETLKW: wait until unlocked
1393 1418 fclose(fptr);
1394   - throw GException::par_file_open_error(G_WRITE, filename,
1395   - "Could not get a lock on the file.");
  1419 + std::string msg = "Could not get a lock on the parameter "
  1420 + "file \""+filename+"\".";
  1421 + throw GException::file_error(G_WRITE, msg);
1396 1422 }
1397 1423 #else
1398 1424 fcntl(fd, F_SETLKW, &lock);
... ... @@ -1415,8 +1441,9 @@ void GApplicationPars::write(const std::string&amp; filename) const
1415 1441 lock.l_type = F_UNLCK;
1416 1442 #if defined(G_CHECK_LOCK_PARFILE)
1417 1443 if (fcntl(fd, F_SETLK, &lock) == -1) {
1418   - throw GException::par_file_open_error(G_WRITE, filename,
1419   - "Could not unlock the file.");
  1444 + std::string msg = "Could not unlock the parameter file \""+
  1445 + filename+"\".";
  1446 + throw GException::file_error(G_WRITE, msg);
1420 1447 }
1421 1448 #else
1422 1449 fcntl(fd, F_SETLK, &lock);
... ... @@ -1434,7 +1461,7 @@ void GApplicationPars::write(const std::string&amp; filename) const
1434 1461 /***********************************************************************//**
1435 1462 * @brief Parse parameter file
1436 1463 *
1437   - * @exception GException::par_file_syntax_error
  1464 + * @exception GException::invalid_value
1438 1465 * Syntax error encountered in parameter file.
1439 1466 *
1440 1467 * The parameter type has to be one b,i,r,s,f,fr,fw,fe,fn. The fr,fw,fe,fn
... ... @@ -1504,23 +1531,30 @@ void GApplicationPars::parse(void)
1504 1531  
1505 1532 // Throw an error if quotes are not balanced
1506 1533 if (quotes != 0) {
1507   - throw GException::par_file_syntax_error(G_PARSE,
1508   - gammalib::strip_chars(line,"\n"),
1509   - "quotes are not balanced");
  1534 + std::string msg = "Quotes are not balanced in the following line "
  1535 + "of the parameter file: "+
  1536 + gammalib::strip_chars(line,"\n")+". Please "
  1537 + "correct the parameter file.";
  1538 + throw GException::invalid_value(G_PARSE, msg);
1510 1539 }
1511 1540  
1512 1541 // Throw an error if line has not 7 fields
1513 1542 if (index != 7) {
1514   - throw GException::par_file_syntax_error(G_PARSE,
1515   - gammalib::strip_chars(line,"\n"),
1516   - "found "+gammalib::str(index)+" fields, require 7");
  1543 + std::string msg = "Number of fields ("+gammalib::str(index)+") "
  1544 + "does not correspond to the expected number of "
  1545 + "7 fields in the following line of the parameter "
  1546 + "file: "+gammalib::strip_chars(line,"\n")+". "
  1547 + "Please correct the parameter file.";
  1548 + throw GException::invalid_value(G_PARSE, msg);
1517 1549 }
1518 1550  
1519 1551 // Verify if parameter name does not yet exist
1520 1552 if (contains(fields[0])) {
1521   - throw GException::par_file_syntax_error(G_PARSE,
1522   - gammalib::strip_chars(line,"\n"),
1523   - "redefinition of parameter name \""+fields[0]+"\"");
  1553 + std::string msg = "Redefinition of parameter name \""+fields[0]+
  1554 + "\" in the following line of the parameter "
  1555 + "file: "+gammalib::strip_chars(line,"\n")+". "
  1556 + "Please correct the parameter file.";
  1557 + throw GException::invalid_value(G_PARSE, msg);
1524 1558 }
1525 1559  
1526 1560 // Add parameter
... ... @@ -1532,10 +1566,12 @@ void GApplicationPars::parse(void)
1532 1566 m_vstart.push_back(vstart);
1533 1567 m_vstop.push_back(vstop);
1534 1568 }
1535   - catch (GException::par_error &e) {
1536   - throw GException::par_file_syntax_error(G_PARSE,
1537   - gammalib::strip_chars(line,"\n"),
1538   - e.what());
  1569 + catch (GException::invalid_value &e) {
  1570 + std::string msg = "Error \""+std::string(e.what())+"\" encountered "
  1571 + "in the following line of the parameter file: "+
  1572 + gammalib::strip_chars(line,"\n")+". "
  1573 + "Please correct the parameter file.";
  1574 + throw GException::invalid_value(G_PARSE, msg);
1539 1575 }
1540 1576  
1541 1577 // If parameter name is mode then store the effective mode
... ... @@ -1543,9 +1579,12 @@ void GApplicationPars::parse(void)
1543 1579 if (fields[3] != "h" && fields[3] != "q" &&
1544 1580 fields[3] != "hl" && fields[3] != "ql" &&
1545 1581 fields[3] != "lh" && fields[3] != "lq") {
1546   - throw GException::par_file_syntax_error(G_PARSE,
1547   - gammalib::strip_chars(line,"\n"),
1548   - "mode parameter has invalid value \""+fields[3]+"\"");
  1582 + std::string msg = "Mode parameter has invalid value \""+
  1583 + fields[3]+"\" in the following line of the "
  1584 + "parameter file: "+
  1585 + gammalib::strip_chars(line,"\n")+". "
  1586 + "Please correct the parameter file.";
  1587 + throw GException::invalid_value(G_PARSE, msg);
1549 1588 }
1550 1589 m_mode = fields[3];
1551 1590 }
... ...
src/app/GException_app.cpp deleted
1   -/***************************************************************************
2   - * GException_app.cpp - Application exception handlers *
3   - * ----------------------------------------------------------------------- *
4   - * copyright (C) 2010-2012 by Juergen Knoedlseder *
5   - * ----------------------------------------------------------------------- *
6   - * *
7   - * This program is free software: you can redistribute it and/or modify *
8   - * it under the terms of the GNU General Public License as published by *
9   - * the Free Software Foundation, either version 3 of the License, or *
10   - * (at your option) any later version. *
11   - * *
12   - * This program is distributed in the hope that it will be useful, *
13   - * but WITHOUT ANY WARRANTY; without even the implied warranty of *
14   - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *
15   - * GNU General Public License for more details. *
16   - * *
17   - * You should have received a copy of the GNU General Public License *
18   - * along with this program. If not, see <http://www.gnu.org/licenses/>. *
19   - * *
20   - ***************************************************************************/
21   -/**
22   - * @file GException_app.cpp
23   - * @brief Application exception handler interface definition
24   - * @author Juergen Knoedlseder
25   - */
26   -
27   -/* __ Includes ___________________________________________________________ */
28   -#ifdef HAVE_CONFIG_H
29   -#include <config.h>
30   -#endif
31   -#include "GException.hpp"
32   -#include "GTools.hpp"
33   -
34   -
35   -/***********************************************************************//**
36   - * @brief Generic application error
37   - *
38   - * @param[in] origin Method that throws the error.
39   - * @param[in] message Optional error message.
40   - ***************************************************************************/
41   -GException::app_error::app_error(const std::string& origin,
42   - const std::string& message)
43   -{
44   - // Set origin
45   - m_origin = origin;
46   -
47   - // Set message
48   - m_message = message;
49   -
50   - // Return
51   - return;
52   -}
53   -
54   -
55   -/***********************************************************************//**
56   - * @brief Parameter file not found
57   - *
58   - * @param[in] origin Method that throws the error.
59   - * @param[in] filename Filename that was not found.
60   - * @param[in] message Optional error message.
61   - ***************************************************************************/
62   -GException::par_file_not_found::par_file_not_found(const std::string& origin,
63   - const std::string& filename,
64   - const std::string& message)
65   -{
66   - // Set origin and message
67   - m_origin = origin;
68   - m_message = "Parameter file \""+filename+"\" not found. "
69   - "Make sure that PFILES environment variable is set "
70   - "correctly.";
71   -
72   - // Add optional error message
73   - if (message.length() > 0) {
74   - m_message += " " + message;
75   - }
76   -
77   - // Return
78   - return;
79   -}
80   -
81   -
82   -/***********************************************************************//**
83   - * @brief Unable to open parameter file
84   - *
85   - * @param[in] origin Method that throws the error.
86   - * @param[in] filename Filename that could not be opened.
87   - * @param[in] message Optional error message.
88   - ***************************************************************************/
89   -GException::par_file_open_error::par_file_open_error(const std::string& origin,
90   - const std::string& filename,
91   - const std::string& message)
92   -{
93   - // Set origin and message
94   - m_origin = origin;
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   - }
101   -
102   - // Return
103   - return;
104   -}
105   -
106   -
107   -/***********************************************************************//**
108   - * @brief Unable to determine users home directory
109   - *
110   - * @param[in] origin Method that throws the error.
111   - * @param[in] message Optional error message.
112   - ***************************************************************************/
113   -GException::home_not_found::home_not_found(const std::string& origin,
114   - const std::string& message)
115   -{
116   - // Set origin and message
117   - m_origin = origin;
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   - }
124   -
125   - // Return
126   - return;
127   -}
128   -
129   -
130   -/***********************************************************************//**
131   - * @brief Unable to create pfiles directory in users home directory
132   - *
133   - * @param[in] origin Method that throws the error.
134   - * @param[in] home Users home directory.
135   - * @param[in] message Optional error message.
136   - ***************************************************************************/
137   -GException::could_not_create_pfiles::could_not_create_pfiles(const std::string& origin,
138   - const std::string& home,
139   - const std::string& message)
140   -{
141   - // Set origin and message
142   - m_origin = origin;
143   - m_message = "Unable to create \""+home+"\".";
144   -
145   - // Add optional error message
146   - if (message.length() > 0) {
147   - m_message += " " + message;
148   - }
149   -
150   - // Return
151   - return;
152   -}
153   -
154   -
155   -/***********************************************************************//**
156   - * @brief Unable to change access rights for pfiles directory
157   - *
158   - * @param[in] origin Method that throws the error.
159   - * @param[in] home Users home directory.
160   - * @param[in] message Optional error message.
161   - ***************************************************************************/
162   -GException::pfiles_not_accessible::pfiles_not_accessible(const std::string& origin,
163   - const std::string& home,
164   - const std::string& message)
165   -{
166   - // Set origin and message
167   - m_origin = origin;
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   - }
175   -
176   - // Return
177   - return;
178   -}
179   -
180   -
181   -/***********************************************************************//**
182   - * @brief Syntax error encountered in parameter file line
183   - *
184   - * @param[in] origin Method that throws the error.
185   - * @param[in] line Parameter file line in which syntax error occured.
186   - * @param[in] message Optional error message.
187   - ***************************************************************************/
188   -GException::par_file_syntax_error::par_file_syntax_error(const std::string& origin,
189   - const std::string& line,
190   - const std::string& message)
191   -{
192   - // Set origin and message
193   - m_origin = origin;
194   - if (message.length() > 0) {
195   - m_message = "Syntax error occured in the following line of the "
196   - "parameter file ("+message+"): "+line;
197   - }
198   - else {
199   - m_message = "Syntax error occured in the following line of the "
200   - "parameter file: "+line;
201   - }
202   -
203   - // Return
204   - return;
205   -}
206   -
207   -
208   -/***********************************************************************//**
209   - * @brief Error encountered in parameter definition
210   - *
211   - * @param[in] origin Method that throws the error.
212   - * @param[in] name Parameter name.
213   - * @param[in] message Optional error message.
214   - ***************************************************************************/
215   -GException::par_error::par_error(const std::string& origin,
216   - const std::string& name,
217   - const std::string& message)
218   -{
219   - // Set origin
220   - m_origin = origin;
221   -
222   - // Set message
223   - m_message = "Parameter \""+name+"\"";
224   -
225   - // Add optional error message
226   - if (message.length() > 0) {
227   - m_message += ": " + message;
228   - }
229   -
230   - // Return
231   - return;
232   -}
233   -
234   -
235   -/***********************************************************************//**
236   - * @brief Invalid command line parameter
237   - *
238   - * @param[in] origin Method that throws the error.
239   - * @param[in] arg Command line argument.
240   - * @param[in] message Optional error message.
241   - ***************************************************************************/
242   -GException::bad_cmdline_argument::bad_cmdline_argument(const std::string& origin,
243   - const std::string& arg,
244   - const std::string& message)
245   -{
246   - // Set origin and message
247   - m_origin = origin;
248   - if (message.length() > 0) {
249   - m_message = "Invalid command line parameter encountered ("+message+
250   - "): "+arg;
251   - }
252   - else {
253   - m_message = "Invalid command line parameter encountered: "+arg;
254   - }
255   -
256   - // Return
257   - return;
258   -}
259   -
src/app/Makefile.am
1 1 #############################################################################
2 2 # Makefile.am for app module #
3 3 # ------------------------------------------------------------------------- #
4   -# Copyright (C) 2016 Juergen Knoedlseder #
  4 +# Copyright (C) 2016-2021 Juergen Knoedlseder #
5 5 # ------------------------------------------------------------------------- #
6 6 # #
7 7 # This program is free software: you can redistribute it and/or modify #
... ... @@ -28,8 +28,7 @@ INCLUDES = -I$(top_srcdir)/include \
28 28 sources = GApplication.cpp \
29 29 GLog.cpp \
30 30 GApplicationPars.cpp \
31   - GApplicationPar.cpp \
32   - GException_app.cpp
  31 + GApplicationPar.cpp
33 32  
34 33 # Build libtool library
35 34 noinst_LTLIBRARIES = libapp.la
... ...