VirtualBox

Changeset 21428 in vbox for trunk


Ignore:
Timestamp:
Jul 9, 2009 11:11:11 AM (16 years ago)
Author:
vboxsync
svn:sync-xref-src-repo-rev:
49816
Message:

Main: remove ENoMemory exception class, replace with std::bad_alloc() to avoid string allocations after memory allocation failed already

Location:
trunk
Files:
4 edited

Legend:

Unmodified
Added
Removed
  • trunk/include/iprt/xml_cpp.h

    r21409 r21428  
    122122    XmlError(xmlErrorPtr aErr);
    123123
    124     static char *Format(xmlErrorPtr aErr);
     124    static char* Format(xmlErrorPtr aErr);
    125125};
    126126
     
    158158// Runtime errors
    159159//////////////////////////////////////////////////////////////////////////////
    160 
    161 class RT_DECL_CLASS ENoMemory : public RuntimeError, public std::bad_alloc
    162 {
    163 public:
    164     ENoMemory(const char *aMsg = NULL) : RuntimeError (aMsg) {}
    165     virtual ~ENoMemory() throw() {}
    166 };
    167160
    168161class RT_DECL_CLASS EIPRTFailure : public RuntimeError
  • trunk/src/VBox/Main/MachineImpl.cpp

    r21404 r21428  
    69756975                                               emptyStr);
    69766976    }
    6977     catch (xml::ENoMemory e)
     6977    catch(std::bad_alloc &e)
    69786978    {
    69796979        return E_OUTOFMEMORY;
  • trunk/src/VBox/Main/xml/Settings.cpp

    r19942 r21428  
    415415            value = xmlEncodeSpecialChars (mNode->doc, value);
    416416            if (value == NULL)
    417                 throw xml::ENoMemory();
     417                throw std::bad_alloc();
    418418        }
    419419
     
    449449                                  (const xmlChar *) aValue);
    450450    if (attr == NULL)
    451         throw xml::ENoMemory();
     451        throw std::bad_alloc();
    452452}
    453453
     
    502502    xmlNodePtr node = xmlNewChild (mNode, NULL, (const xmlChar *) aName, NULL);
    503503    if (node == NULL)
    504         throw xml::ENoMemory();
     504        throw std::bad_alloc();
    505505
    506506    return Key (new XmlKeyBackend (node));
     
    584584    m->ctxt = xmlNewParserCtxt();
    585585    if (m->ctxt == NULL)
    586         throw xml::ENoMemory();
     586        throw std::bad_alloc();
    587587}
    588588
     
    11481148        delete ctxt;
    11491149
    1150         throw xml::ENoMemory();
     1150        throw std::bad_alloc();
    11511151    }
    11521152    catch (const xml::EIPRTFailure &err) { sThat->m->trappedErr.reset (stdx::new_exception_trap (err)); }
  • trunk/src/VBox/Runtime/r3/xml.cpp

    r21409 r21428  
    168168{
    169169    Data()
    170         : fileName (NULL), handle (NIL_RTFILE), opened (false) {}
    171 
    172     char *fileName;
     170        : handle(NIL_RTFILE), opened(false)
     171    { }
     172
     173    iprt::MiniString strFileName;
    173174    RTFILE handle;
    174175    bool opened : 1;
     
    176177
    177178File::File(Mode aMode, const char *aFileName)
    178     : m (new Data())
    179 {
    180     m->fileName = RTStrDup (aFileName);
    181     if (m->fileName == NULL)
    182         throw ENoMemory();
     179    : m(new Data())
     180{
     181    m->strFileName = aFileName;
    183182
    184183    unsigned flags = 0;
     
    205204}
    206205
    207 File::File (RTFILE aHandle, const char *aFileName /* = NULL */)
    208     : m (new Data())
     206File::File(RTFILE aHandle, const char *aFileName /* = NULL */)
     207    : m(new Data())
    209208{
    210209    if (aHandle == NIL_RTFILE)
     
    214213
    215214    if (aFileName)
    216     {
    217         m->fileName = RTStrDup (aFileName);
    218         if (m->fileName == NULL)
    219             throw ENoMemory();
    220     }
     215        m->strFileName = aFileName;
    221216
    222217    setPos (0);
     
    226221{
    227222    if (m->opened)
    228         RTFileClose (m->handle);
    229 
    230     RTStrFree (m->fileName);
    231 }
    232 
    233 const char *File::uri() const
    234 {
    235     return m->fileName;
     223        RTFileClose(m->handle);
     224}
     225
     226const char* File::uri() const
     227{
     228    return m->strFileName.c_str();
    236229}
    237230
     
    796789    if (!(plibNode = xmlNewNode(NULL,        // namespace
    797790                                (const xmlChar*)pcszElementName)))
    798         throw ENoMemory();
     791        throw std::bad_alloc();
    799792    xmlAddChild(m->plibNode, plibNode);
    800793
     
    823816    xmlNode *plibNode;
    824817    if (!(plibNode = xmlNewText((const xmlChar*)pcszContent)))
    825         throw ENoMemory();
     818        throw std::bad_alloc();
    826819    xmlAddChild(m->plibNode, plibNode);
    827820
     
    10461039    if (!(plibRootNode = xmlNewNode(NULL,        // namespace
    10471040                                    (const xmlChar*)pcszRootElementName)))
    1048         throw ENoMemory();
     1041        throw std::bad_alloc();
    10491042    xmlDocSetRootElement(m->plibDocument, plibRootNode);
    10501043
     
    10671060    m_ctxt = xmlNewParserCtxt();
    10681061    if (m_ctxt == NULL)
    1069         throw ENoMemory();
     1062        throw std::bad_alloc();
    10701063}
    10711064
     
    10901083    {
    10911084        if (!(ctxt = xmlNewParserCtxt()))
    1092             throw xml::ENoMemory();
     1085            throw std::bad_alloc();
    10931086    }
    10941087
Note: See TracChangeset for help on using the changeset viewer.

© 2025 Oracle Support Privacy / Do Not Sell My Info Terms of Use Trademark Policy Automated Access Etiquette