Changeset 1477


Ignore:
Timestamp:
04/12/18 11:12:11 (6 years ago)
Author:
oabramkina
Message:

Implementing exception handling for accessing attribute value.

In certain cases attribute's id will be printed in the error message.

Location:
XIOS
Files:
4 edited

Legend:

Unmodified
Added
Removed
  • XIOS/dev/XIOS_DEV_CMIP6/src/attribute_template_impl.hpp

    r1158 r1477  
    7171         T CAttributeTemplate<T>::getValue(void) const 
    7272      { 
    73         return CType<T>::get() ; 
     73        try { 
     74          return CType<T>::get() ; 
     75        } 
     76        catch (xios::CException & exc) 
     77        { 
     78          StdString msg("On checking attribute with id="); 
     79          msg.append(this->getId()); 
     80          msg.append(" : "); 
     81          msg.append("data is not initialized\n"); 
     82          ERROR("template <typename T> void CType<T>::checkEmpty(void) const", << msg); 
     83        } 
     84 
    7485/* 
    7586        if (SuperClass::isEmpty()) 
  • XIOS/dev/XIOS_DEV_CMIP6/src/type/type_impl.hpp

    r1158 r1477  
    122122   CType<T>::operator T&() 
    123123   { 
    124     checkEmpty(); 
     124     try 
     125     { 
     126       checkEmpty(); 
     127     } 
     128     catch (xios::CException & exc) 
     129     { 
     130       StdString msg("Data is not initialized\n"); 
     131       ERROR("template <typename T> void CType<T>::checkEmpty(void) const", << msg); 
     132     } 
     133 
    125134    return *ptrValue ; 
    126135   } 
     
    208217  void CType<T>::checkEmpty(void) const 
    209218  { 
    210     if (empty) ERROR("template <typename T> void CType<T>::checkEmpty(void) const", << "Data is not initialized") ; 
     219//    if (empty) ERROR("template <typename T> void CType<T>::checkEmpty(void) const", << "Data is not initialized") ; 
     220    if (empty) throw CException(); 
    211221  } 
    212222 
  • XIOS/trunk/src/attribute_template_impl.hpp

    r1117 r1477  
    7171         T CAttributeTemplate<T>::getValue(void) const 
    7272      { 
    73         return CType<T>::get() ; 
     73        try { 
     74          return CType<T>::get() ; 
     75        } 
     76        catch (xios::CException & exc) 
     77        { 
     78          StdString msg("On checking attribute with id="); 
     79          msg.append(this->getId()); 
     80          msg.append(" : "); 
     81          msg.append("data is not initialized\n"); 
     82          ERROR("template <typename T> void CType<T>::checkEmpty(void) const", << msg); 
     83        } 
     84 
    7485/* 
    7586        if (SuperClass::isEmpty()) 
  • XIOS/trunk/src/type/type_impl.hpp

    r1105 r1477  
    122122   CType<T>::operator T&() 
    123123   { 
    124     checkEmpty(); 
     124     try 
     125     { 
     126       checkEmpty(); 
     127     } 
     128     catch (xios::CException & exc) 
     129     { 
     130       StdString msg("Data is not initialized\n"); 
     131       ERROR("template <typename T> void CType<T>::checkEmpty(void) const", << msg); 
     132     } 
     133 
    125134    return *ptrValue ; 
    126135   } 
     
    208217  void CType<T>::checkEmpty(void) const 
    209218  { 
    210     if (empty) ERROR("template <typename T> void CType<T>::checkEmpty(void) const", << "Data is not initialized") ; 
     219//    if (empty) ERROR("template <typename T> void CType<T>::checkEmpty(void) const", << "Data is not initialized") ; 
     220    if (empty) throw CException(); 
    211221  } 
    212222 
Note: See TracChangeset for help on using the changeset viewer.