VirtualBox

Changeset 27418 in vbox for trunk/src/VBox/Runtime


Ignore:
Timestamp:
Mar 16, 2010 5:30:50 PM (15 years ago)
Author:
vboxsync
Message:

IPRT: much better error messages for XML runtime errors (improves greatly the 'inaccessible' message when a machine XML is missing)

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/VBox/Runtime/r3/xml.cpp

    r26344 r27418  
    149149}
    150150
    151 EIPRTFailure::EIPRTFailure(int aRC)
     151EIPRTFailure::EIPRTFailure(int aRC, const char *pcszContext, ...)
    152152    : RuntimeError(NULL),
    153153      mRC(aRC)
    154154{
    155     char *newMsg = NULL;
    156     RTStrAPrintf(&newMsg, "Runtime error: %d (%s)", aRC, RTErrGetShort(aRC));
     155    char *pszContext2;
     156    va_list args;
     157    va_start(args, pcszContext);
     158    RTStrAPrintfV(&pszContext2, pcszContext, args);
     159    char *newMsg;
     160    RTStrAPrintf(&newMsg, "%s: %d (%s)", pszContext2, aRC, RTErrGetShort(aRC));
    157161    setWhat(newMsg);
    158162    RTStrFree(newMsg);
     163    RTStrFree(pszContext2);
    159164}
    160165
     
    200205    int vrc = RTFileOpen(&m->handle, aFileName, flags);
    201206    if (RT_FAILURE(vrc))
    202         throw EIPRTFailure(vrc);
     207        throw EIPRTFailure(vrc, "Runtime error opening '%s' for reading", aFileName);
    203208
    204209    m->opened = true;
     
    234239{
    235240    uint64_t p = 0;
    236     int vrc = RTFileSeek (m->handle, 0, RTFILE_SEEK_CURRENT, &p);
    237     if (RT_SUCCESS (vrc))
     241    int vrc = RTFileSeek(m->handle, 0, RTFILE_SEEK_CURRENT, &p);
     242    if (RT_SUCCESS(vrc))
    238243        return p;
    239244
    240     throw EIPRTFailure (vrc);
    241 }
    242 
    243 void File::setPos (uint64_t aPos)
     245    throw EIPRTFailure(vrc, "Runtime error seeking in file '%s'", m->strFileName.c_str());
     246}
     247
     248void File::setPos(uint64_t aPos)
    244249{
    245250    uint64_t p = 0;
     
    250255    if (((int64_t) aPos) < 0)
    251256    {
    252         vrc = RTFileSeek (m->handle, INT64_MAX, method, &p);
    253         aPos -= (uint64_t) INT64_MAX;
     257        vrc = RTFileSeek(m->handle, INT64_MAX, method, &p);
     258        aPos -= (uint64_t)INT64_MAX;
    254259        method = RTFILE_SEEK_CURRENT;
    255260    }
    256261    /* seek the rest */
    257     if (RT_SUCCESS (vrc))
    258         vrc = RTFileSeek (m->handle, (int64_t) aPos, method, &p);
    259     if (RT_SUCCESS (vrc))
     262    if (RT_SUCCESS(vrc))
     263        vrc = RTFileSeek(m->handle, (int64_t) aPos, method, &p);
     264    if (RT_SUCCESS(vrc))
    260265        return;
    261266
    262     throw EIPRTFailure (vrc);
    263 }
    264 
    265 int File::read (char *aBuf, int aLen)
     267    throw EIPRTFailure(vrc, "Runtime error seeking in file '%s'", m->strFileName.c_str());
     268}
     269
     270int File::read(char *aBuf, int aLen)
    266271{
    267272    size_t len = aLen;
    268     int vrc = RTFileRead (m->handle, aBuf, len, &len);
    269     if (RT_SUCCESS (vrc))
     273    int vrc = RTFileRead(m->handle, aBuf, len, &len);
     274    if (RT_SUCCESS(vrc))
    270275        return (int)len;
    271276
    272     throw EIPRTFailure (vrc);
    273 }
    274 
    275 int File::write (const char *aBuf, int aLen)
     277    throw EIPRTFailure(vrc, "Runtime error reading from file '%s'", m->strFileName.c_str());
     278}
     279
     280int File::write(const char *aBuf, int aLen)
    276281{
    277282    size_t len = aLen;
     
    280285        return (int)len;
    281286
    282     throw EIPRTFailure (vrc);
     287    throw EIPRTFailure(vrc, "Runtime error writing to file '%s'", m->strFileName.c_str());
    283288
    284289    return -1 /* failure */;
     
    291296        return;
    292297
    293     throw EIPRTFailure (vrc);
     298    throw EIPRTFailure(vrc, "Runtime error truncating file '%s'", m->strFileName.c_str());
    294299}
    295300
Note: See TracChangeset for help on using the changeset viewer.

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