Информация об изменениях

Сообщение Re[7]: Исключения в C++ от 26.03.2016 22:08

Изменено 26.03.2016 22:47 ononim

_>Нет проблем. Только кому это надо?

...проще надо быть
#define RETRY(ATTEMPTS) for(int try_attempt##__LINE__ = 0; try_attempt##__LINE__ <= ATTEMPTS; ++try_attempt##__LINE__) try {
#define CATCH(E) break; } catch(E) {
#define DONE }

int _tmain(int argc, _TCHAR* argv[])
{
    RETRY(3)
    if (--argc) throw std::exception("world");
    printf("done\n");
    CATCH(std::exception &e)
    printf("hello %s\n", e.what());
    DONE
    return 0;
}

но все равно это костыль имхо
Re[7]: Исключения в C++
_>Нет проблем. Только кому это надо?

...проще надо быть
#define RETRY(ATTEMPTS) for(int try_attempt = 0; try_attempt <= ATTEMPTS; ++try_attempt) try {
#define CATCH(E) break; } catch(E) {
#define DONE }

int _tmain(int argc, _TCHAR* argv[])
{
    RETRY(3)
    {
        if (--argc) throw std::exception("world");
        printf("done\n");
    }
    CATCH(std::exception &e)
    {
        printf("hello %s\n", e.what());
    }
    DONE
    return 0;
}

или со строгим киданием исключения выше:

#define RETRY(ATTEMPTS) for(int try_attempt = 0, max_attempt = ATTEMPTS; ; ++try_attempt) try {
#define REPAIR(E); break; } catch(E) { if (try_attempt == max_attempt) throw;
#define DONE }

int _tmain(int argc, _TCHAR* argv[])
{
    RETRY(3)
    {
        if (--argc) throw std::exception("world");
        printf("done\n");
    }
    REPAIR(std::exception &e)
    {
        printf("hello %s\n", e.what());
    }
    DONE
    return 0;
}

но все равно это костыль имхо