Changeset 7817 for trunk


Ignore:
Timestamp:
11/24/11 15:58:03 (8 years ago)
Author:
mario
Message:

added in idea of exception handling between Java and C++ exec methods

Location:
trunk/legacy/jvmlink/src/main
Files:
3 edited

Legend:

Unmodified
Added
Removed
  • trunk/legacy/jvmlink/src/main/c++/JVMLinkClient.cpp

    r7813 r7817  
    5454//TODO: clear memory at appropriate points. 
    5555 
     56JVMException::JVMException(const std::string& aMessage) throw() 
     57{ 
     58        mMessage = aMessage; 
     59} 
     60 
     61JVMException::~JVMException() throw() 
     62{ 
     63} 
     64 
     65const char* JVMException::what() const throw() 
     66{ 
     67        return mMessage.c_str(); 
     68} 
     69 
     70 
    5671JVMLinkClient::JVMLinkClient(void) 
    5772{ 
     
    6479// -- Public API methods -- 
    6580 
    66 void JVMLinkClient::startJava(int arg_port, const std::string& classpath) { 
     81void JVMLinkClient::startJava(unsigned short arg_port, const std::string& classpath) { 
    6782        port = arg_port == 0 ? DEFAULT_PORT : arg_port; 
    6883        std::stringstream tmpportstr; 
     
    235250        sendInt(EXEC_CMD); 
    236251        sendMessage(command); 
     252        int status = readInt(); 
     253        if (status != 0) { 
     254                std::string vMessage = *readString(); 
     255                JVMException vJVMException(vMessage); 
     256                throw vJVMException; 
     257        } 
    237258} 
    238259 
  • trunk/legacy/jvmlink/src/main/c++/JVMLinkClient.h

    r7813 r7817  
    4242//#define debug(msg) std::cout << "JVMLinkClient: " << msg << std::endl 
    4343 
     44class JVMException : public std::exception 
     45{ 
     46public: 
     47        JVMException(const std::string& aMessage) throw (); 
     48        virtual ~JVMException() throw (); 
     49 
     50        virtual const char* what() const throw(); 
     51 
     52private: 
     53        std::string mMessage; 
     54}; 
     55 
     56 
    4457class JVMLinkClient 
    4558{ 
    4659private: 
    47         int port; 
     60        unsigned short port; 
    4861#ifdef _WIN32 
    4962        SOCKET conn; 
     
    6881 
    6982        JVMLinkClient(); 
    70         void startJava(int, const std::string&); 
     83        void startJava(unsigned short, const std::string&); 
    7184        void shutJava(); 
    7285        ConnectionCode establishConnection(); 
  • trunk/legacy/jvmlink/src/main/java/loci/jvmlink/ConnThread.java

    r7816 r7817  
    685685    String cmd = readString(); 
    686686    debug("exec: " + cmd); 
    687     r.exec(cmd); 
     687    try { 
     688      r.exec(cmd); 
     689      writeInt(0); 
     690      out.flush(); 
     691    } catch (ReflectException exc) { 
     692      writeInt(1); 
     693      out.flush(); 
     694      writeString(exc.getMessage()); 
     695      out.flush(); 
     696 
     697      throw exc; 
     698    } 
    688699  } 
    689700 
Note: See TracChangeset for help on using the changeset viewer.