среда, 1 августа 2012 г.

exception: handling

Стратегии обработки
- позволить лететь вверх (не восстанавливаем контекст)
- перехватить и бросить опять ( восстанавливаем  контекст)
- перехватить , обернуть, бросить (восстановить контекст, добавить контекстную информацию)
- перехватить и обработать 
- идиома try-finally
        lock.lock();
        try {
            ...
        } finally {
            lock.unlock();
        }

Принципы обработки

The following are some of the generally accepted principles of exception handling:
  1. If you can't handle an exception, don't catch it.
  2. If you catch an exception, don't swallow it.
  3. Catch an exception as close as possible to its source.
  4. Log an exception where you catch it, unless you plan to rethrow it.
  5. Structure your methods according to how fine-grained your exception handling must be.
  6. Use as many typed exceptions as you need, particularly for application exceptions.
Point 1 is obviously in conflict with Point 3. The practical solution is a trade-off between how close to the source you catch an exception and how far you let it fall before you've completely lost the intent or content of the original exception.

    Лабораторные
    ex.strategy.atomix_tx
    ex.strategy.spinup_chained
    Задания лабораторных можно прочитать на этой странице.