Changeset 1400:aa7829bd0b9c


Ignore:
Timestamp:
11/07/09 21:50:59 (2 years ago)
Author:
niam
Branch:
default
Message:

{issue #45[resolved]} saved uncought exception thrown by thread routine for later examination

Location:
src
Files:
4 edited

Legend:

Unmodified
Added
Removed
  • src/examples/pc_thread/test.cc

    r1397 r1400  
    3131        cout.flush(); 
    3232    } catch (dodo::exception::basic &ex)   { 
    33         cout << (dodoString)ex << ex.line << endl; 
     33        cout << (dodoString)ex << "\t" << ex.line << "\t" << ex.file << endl; 
    3434    } 
     35 
     36    // throwing exception 
     37    tools::os::os::setWorkingDir("./dir/"); 
    3538 
    3639    return 0; 
     
    6669        manager.wait(); 
    6770 
     71        for (int i = 0; i < amount; ++i) { 
     72            dodo::exception::basic *ex = manager.job(pos[i])->exception(); 
     73            if (ex) { 
     74                cout << "Thread " << i << ":\t" << (dodoString)*ex << "\t" << ex->line << "\t" << ex->file << endl; 
     75            } 
     76        } 
     77 
    6878        delete data; 
    6979    } catch (dodo::exception::basic &ex)   { 
    70         cout << (dodoString)ex << endl; 
     80        cout << (dodoString)ex << "\t" << ex.line << "\t" << ex.file << endl; 
    7181    } 
    7282 
  • src/include/libdodo/exceptionBasic.h

    r1386 r1400  
    143143          public: 
    144144 
    145 #ifdef DL_EXT 
    146             /** 
    147              * @struct __module__ 
    148              * @brief is returned from initModule in the library 
    149              */ 
    150             struct __module__ { 
    151                 char name[64];                              ///< name of the library 
    152                 char discription[256];                      ///< discription of the library 
    153                 char hook[64];                              ///< name of the function in module that will be as a hook 
    154                 char cookie[32];                            ///< cookie that would be passed to deinitModule 
    155                 bool modules[MODULE_ENUMSIZE];              ///< for what modules handler should be set, @see exception::moduleEnum 
    156             }; 
    157  
    158             /** 
    159              * @typedef initModule 
    160              * @brief defines type of init function for library 
    161              * @param data defines user data 
    162              * @note name in the library must be initExceptionBasicModule 
    163              */ 
    164             typedef __module__ (*initModule)(void *data); 
    165  
    166             /** 
    167              * @typedef deinitModule 
    168              * @brief defines type of deinit function for library 
    169              * @param cookie defines cookie data returned from initModule 
    170              * @note name in the library must be deinitExceptionBasicModule 
    171              */ 
    172             typedef void (*deinitModule)(char cookie[32]); 
    173 #endif 
    174  
    175             /** 
    176              * @typedef handler 
    177              * @brief defines type of hook function 
    178              * @param module defines module where exception occured, @see exception::moduleEnum 
    179              * @param ex defines pointer to basic object with exception information 
    180              * @param data defines user data 
    181              */ 
    182             typedef void (*handler)(int module, basic *ex, void *data); 
    183  
    184145            /** 
    185146             * constructor 
     
    207168            ~basic() throw (); 
    208169 
     170#ifdef DL_EXT 
     171            /** 
     172             * @struct __module__ 
     173             * @brief is returned from initModule in the library 
     174             */ 
     175            struct __module__ { 
     176                char name[64];                              ///< name of the library 
     177                char discription[256];                      ///< discription of the library 
     178                char hook[64];                              ///< name of the function in module that will be as a hook 
     179                char cookie[32];                            ///< cookie that would be passed to deinitModule 
     180                bool modules[MODULE_ENUMSIZE];              ///< for what modules handler should be set, @see exception::moduleEnum 
     181            }; 
     182 
     183            /** 
     184             * @typedef initModule 
     185             * @brief defines type of init function for library 
     186             * @param data defines user data 
     187             * @note name in the library must be initExceptionBasicModule 
     188             */ 
     189            typedef __module__ (*initModule)(void *data); 
     190 
     191            /** 
     192             * @typedef deinitModule 
     193             * @brief defines type of deinit function for library 
     194             * @param cookie defines cookie data returned from initModule 
     195             * @note name in the library must be deinitExceptionBasicModule 
     196             */ 
     197            typedef void (*deinitModule)(char cookie[32]); 
     198#endif 
     199 
     200            /** 
     201             * @typedef handler 
     202             * @brief defines type of hook function 
     203             * @param module defines module where exception occured, @see exception::moduleEnum 
     204             * @param ex defines pointer to basic object with exception information 
     205             * @param data defines user data 
     206             */ 
     207            typedef void (*handler)(int module, basic *ex, void *data); 
     208 
    209209            /** 
    210210             * @return error string 
  • src/include/libdodo/pcExecutionThread.h

    r1386 r1400  
    3737 
    3838namespace dodo { 
     39    namespace exception { 
     40        class basic; 
     41    }; 
     42 
    3943    namespace pc { 
    4044        namespace execution { 
     
    105109                virtual bool isRunning() const; 
    106110 
     111                /** 
     112                 * @return uncought exception thrown by thread routine 
     113                 */ 
     114                virtual exception::basic *exception(); 
     115 
    107116#ifdef DL_EXT 
    108117                /** 
  • src/src/pcExecutionThread.cc

    r1386 r1400  
    4141 
    4242namespace dodo { 
     43    namespace exception { 
     44        class basic; 
     45    }; 
     46 
    4347    namespace pc { 
    4448        namespace execution { 
     
    5761                    executed(false), 
    5862                    joined(false), 
    59                     status(0) 
     63                    status(0), 
     64                    ex(NULL) 
    6065#ifdef DL_EXT 
    6166                    , 
     
    7984#endif 
    8085 
     86                void           *func;               ///< function to execute 
    8187                void           *data;               ///< thread data 
     88 
    8289                bool           executed;            ///< true if thread is running 
    8390                bool           joined;              ///< true if the thread was joined 
    8491                int            status;              ///< thread exit status 
    8592                bool           detached;            ///< true if thread is detached 
    86                 void           *func;               ///< function to execute 
    8793                short          action;              ///< action on object destruction[@see onDestructionEnum] 
     94 
     95                exception::basic *ex; ///< uncought exception thrown by thread routine 
     96 
    8897#ifdef DL_EXT 
    8998                void           *handle;             ///< handle to library 
     
    100109#include <libdodo/pcExecutionThreadEx.h> 
    101110#include <libdodo/types.h> 
     111#include <libdodo/exceptionBasic.h> 
    102112 
    103113using namespace dodo::pc::execution; 
     
    109119    __thread__ *ti = (__thread__ *)data; 
    110120 
    111     ti->status = ((execution::routine)ti->func)(ti->data); 
     121    try { 
     122        delete ti->ex; 
     123        ti->ex = NULL; 
     124 
     125        ti->status = ((execution::routine)ti->func)(ti->data); 
     126    } catch (exception::basic &ex) { 
     127        ti->ex = new exception::basic(ex); 
     128        ti->status = 0; 
     129    } 
    112130 
    113131    return NULL; 
     
    283301    } 
    284302 
     303    delete handle->ex; 
     304 
    285305    delete handle; 
    286306} 
     
    408428 
    409429//------------------------------------------------------------------- 
     430 
     431dodo::exception::basic * 
     432thread::exception() 
     433{ 
     434    return handle->ex; 
     435} 
     436 
     437//------------------------------------------------------------------- 
Note: See TracChangeset for help on using the changeset viewer.