Неплохое решение для дизайна бросить исключение из доступа?

Я прочитал некоторые ответы Re Pro's и Con of the Grading исключение внутри доступа, но я подумал, что я протянул свой конкретный вопрос на примере:

public class App {
  static class Test {       
    private List<String> strings;

    public Test() {
    }

    public List<String> getStrings() throws Exception {
        if (this.strings == null)
            throw new Exception();

        return strings;
    }

    public void setStrings(List<String> strings) {
        this.strings = strings;
    }
}

public static void main(String[] args) {
    Test t = new Test();

    List<String> s = null;
    try {
        s = t.getStrings();
    } catch (Exception e) {
        // TODO: do something more specific
    }
  }
}

GetStrings () Образуется исключение , когда строки не было установлено. Будет ли эта ситуация лучше обрабатываться методом?

6
задан wulfgarpro 7 September 2011 в 13:05
поделиться