Ignore:
Timestamp:
12/11/18 13:22:07 (6 years ago)
Author:
oabramkina
Message:

Exception handling on trunk.

To activate it, compilation flag -DXIOS_EXCEPTION should be added.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • XIOS/trunk/src/xml_parser.cpp

    r1158 r1622  
    1414 
    1515      void CXMLParser::ParseFile(const StdString & filename, const std::set<StdString>& parseContextList) 
     16      TRY 
    1617      { 
    1718         StdIFStream ifs ( filename.c_str() , StdIFStream::in ); 
     
    2223         CXMLParser::ParseStream(ifs, filename, parseContextList); 
    2324      } 
     25      CATCH 
    2426 
    2527      void CXMLParser::ParseString(const StdString & xmlContent) 
     
    5456            std::set<StdString>::const_iterator itE = parseContextList.end(); 
    5557            bool isParseAll = (parseContextList.empty()); 
    56             if (node.goToChildElement()) 
     58            try 
    5759            { 
    58                do 
    59                { 
    60                   CContextGroup* group_context = CContext::getRoot() ; 
     60              if (node.goToChildElement()) 
     61              { 
     62                 do 
     63                 { 
     64                    CContextGroup* group_context = CContext::getRoot() ; 
    6165 
    62                   attributes = node.getAttributes(); 
     66                    attributes = node.getAttributes(); 
    6367 
    64                   if (attributes.end() == attributes.find("id")) 
    65                   { 
    66                      DEBUG("The context will not be processed because it is not identified (missing id)"); 
    67                      continue; 
    68                   } 
     68                    if (attributes.end() == attributes.find("id")) 
     69                    { 
     70                       DEBUG("The context will not be processed because it is not identified (missing id)"); 
     71                       continue; 
     72                    } 
    6973 
    70                   CContext::setCurrent(attributes["id"]) ; 
     74                    CContext::setCurrent(attributes["id"]) ; 
    7175 
    72  
    73                   if (isParseAll) 
    74                   { 
    75                     CContext* context = CContext::create(attributes["id"]); 
    76                     context->parse(node); 
    77  
    78                     attributes.clear(); 
    79                   } 
    80                   else 
    81                   { 
    82                     it = parseContextList.find(attributes["id"]); 
    83                     if (itE != it) 
     76                    if (isParseAll) 
    8477                    { 
    85                       CContext* context = CContext::create(*it); 
     78                      CContext* context = CContext::create(attributes["id"]); 
    8679                      context->parse(node); 
    8780 
    8881                      attributes.clear(); 
    8982                    } 
    90                   } 
    91                } while (node.goToNextElement()); 
     83                    else 
     84                    { 
     85                      it = parseContextList.find(attributes["id"]); 
     86                      if (itE != it) 
     87                      { 
     88                        CContext* context = CContext::create(*it); 
     89                        context->parse(node); 
     90 
     91                        attributes.clear(); 
     92                      } 
     93                    } 
     94                 } while (node.goToNextElement()); 
     95              } 
    9296            } 
     97            catch(CException& e) 
     98            { 
     99              CException::StackInfo stk; 
     100              stk.info.append("Exception occurred while parsing XML file \""); 
     101              stk.info.append(attributes["src"]); 
     102              stk.info.append("\".\n"); 
     103              stk.file = FILE_NAME; 
     104              stk.function = FUNCTION_NAME; 
     105              stk.line = __LINE__; 
     106              e.stack.push_back(stk); 
     107              if (CXios::xiosStack) 
     108                throw; 
     109             else 
     110               throw 0; 
     111            } 
     112            catch(...) 
     113            { 
     114              CException exc; 
     115              CException::StackInfo stk; 
     116              stk.info.append("Exception occurred while parsing XML file \""); 
     117              stk.info.append(attributes["src"]); 
     118              stk.info.append("\".\n"); 
     119              stk.file = FILE_NAME; 
     120              stk.function = FUNCTION_NAME; 
     121              stk.line = __LINE__; 
     122              exc.stack.push_back(stk); 
     123              if (CXios::xiosStack) 
     124                throw exc; 
     125             else 
     126               throw 0; 
     127            } 
     128 
    93129         } 
    94130         catch (rapidxml::parse_error & exc) 
     
    110146                  << "Error is occuring when parsing XML flux from <"<<fluxId<<"> at character "<< pos<<" line "<<lineNumber<<" column "<< columnNumber<< endl 
    111147                  << strLine<<endl 
    112                   << string(columnNumber-1,'x')<<'^'<<endl 
    113                   <<" Error : " << exc.what() ) 
     148                  << string(columnNumber-1,'x')<<'^'<<endl) 
     149//                  <<" Error : " << exc.what() ) 
    114150         } 
    115151      } 
Note: See TracChangeset for help on using the changeset viewer.