Changeset 1178 for trunk/yat


Ignore:
Timestamp:
Feb 27, 2008, 8:24:31 PM (16 years ago)
Author:
Peter
Message:

fixes #344

Location:
trunk/yat/utility
Files:
6 edited

Legend:

Unmodified
Added
Removed
  • trunk/yat/utility/CommandLine.cc

    r1000 r1178  
    2525
    2626#include "ColumnStream.h"
     27#include "Exception.h"
    2728#include "Option.h"
    2829#include "OptionSwitch.h"
     
    115116            ss << ": unrecognized option `" << key << "'\n"
    116117               << try_help();
    117             throw std::runtime_error(ss.str());
     118            throw cmd_error(ss.str());
    118119          }
    119120          else
     
    129130              ss << ": invalid option -- " << (*arg)[i] << "\n"
    130131                 << try_help() << "\n";
    131               throw std::runtime_error(ss.str());
     132              throw cmd_error(ss.str());
    132133            }       
    133134            else
     
    139140               std::mem_fun(&Option::validate));
    140141    }
    141     catch (std::runtime_error& e){
     142    catch (cmd_error& e){
    142143      std::stringstream ss;
    143144      ss << program_name_ << ": " << e.what();
    144       throw std::runtime_error(ss.str());
     145      throw cmd_error(ss.str());
    145146    }
    146147     
  • trunk/yat/utility/CommandLine.h

    r1000 r1178  
    2424  02111-1307, USA.
    2525*/
    26 
    27 #include "TypeInfo.h"
    2826
    2927#include <cctype>
     
    6260       cmd.parse(argc, argv);
    6361     }
    64      catch (std::runtime_error e){
     62     catch (cmd_error e){
    6563       std::cout << e.what() << std::endl;
    6664       return 1;
     
    112110       \brief parse the commandline
    113111
    114        throw std::runtime_error if an error is detected.
     112       throw cmd_error if an error is detected.
    115113    */
    116114    void parse(int argc, char* argv[]);
  • trunk/yat/utility/Exception.h

    r1000 r1178  
    3434namespace yat {
    3535namespace utility {
     36
     37  /**
     38     \brief Class used for error reported from Commandline or Option.
     39   */
     40  class cmd_error : public std::runtime_error
     41  {
     42  public:
     43    inline cmd_error(std::string message)
     44      : std::runtime_error(message) {}
     45  };
     46
    3647
    3748  /**
  • trunk/yat/utility/Option.cc

    r1000 r1178  
    8484    present_=true;
    8585    do_parse(first, last);
     86    std::cerr << "parsed " << long_name() << std::endl;
    8687  }
    8788
     
    147148  void Option::validate()
    148149  {
     150    std::cerr << "validate: " << long_name() << std::endl;
    149151    do_validate();
    150152  }
  • trunk/yat/utility/OptionArg.h

    r1125 r1178  
    2727#include "Option.h"
    2828#include "CommandLine.h"
     29#include "Exception.h"
    2930
    30 #include <stdexcept>
    3131#include <string>
    3232#include <sstream>
     
    8787        ss << "option requires an argument -- " << short_name() << "\n"
    8888           << cmd().try_help();
    89         throw std::runtime_error(ss.str());
     89        throw cmd_error(ss.str());
    9090      }
    9191      if (first+1==last ) {
     
    9494          ss << "option `--" << long_name() << "' requires an argument\n"
    9595             << cmd().try_help();
    96           throw std::runtime_error(ss.str());
     96          throw cmd_error(ss.str());
    9797        }
    9898        else {
     
    100100          ss << "option requires an argument -- " << short_name() << "\n"
    101101             << cmd().try_help();
    102           throw std::runtime_error(ss.str());
     102          throw cmd_error(ss.str());
    103103        }
    104104      }       
     
    125125        std::stringstream sstr(rhs);
    126126        sstr << ": invalid argument";
    127         throw std::runtime_error(sstr.str());
     127        throw cmd_error(sstr.str());
    128128      }
    129129    }
     
    142142        ss << "' not given\n";
    143143        ss << cmd().try_help();
    144         throw std::runtime_error(ss.str());
     144        throw cmd_error(ss.str());
    145145      }
    146146      do_validate2();
  • trunk/yat/utility/OptionFile.cc

    r1014 r1178  
    2323
    2424#include "OptionFile.h"
     25#include "Exception.h"
    2526#include "FileUtil.h"
    2627
    27 #include <stdexcept>
    2828#include <string>
    2929
     
    4646  void OptionFile::do_validate2() const
    4747  {   
     48    std::cerr << "OptionFile:: do_validate2 " << std::endl;
    4849    if (!present())
    4950      return;
    5051    FileUtil fu(value().c_str());
     52    std::cerr << "check exist" << std::endl;
    5153    if (exist_ && !fu.exists()){
    5254      std::stringstream ss;
    5355      ss << "cannot stat `" << value() << "': No such file or directory";
    54       throw std::runtime_error(ss.str());
     56      throw cmd_error(ss.str());
    5557    }
     58    std::cerr << "check perm" << std::endl;
    5659    if (fu.permissions(bits_)) {
    5760      // Peter, this loop is stupid but I wanna differentiate the error message
     
    6063          std::stringstream ss;
    6164          ss << "cannot stat `" << value() << "': No such file or directory";
    62           throw std::runtime_error(ss.str());
     65          throw cmd_error(ss.str());
    6366        }
    6467        else if (*iter=='w' && fu.permissions("w")){
     
    6669          ss << "cannot create file `" << value()
    6770             << "': Permission denied";
    68           throw std::runtime_error(ss.str());
     71          throw cmd_error(ss.str());
    6972        }
    7073      }
    7174      std::stringstream ss;
    7275      ss << value() << ": Permission denied";
    73       throw std::runtime_error(ss.str());
     76      throw cmd_error(ss.str());
    7477    }
    7578  }
Note: See TracChangeset for help on using the changeset viewer.