Поскольку, когда та одна одна строка выдает исключение, Вы не знали бы это.
С первым блоком кода, исключение просто будет , поглотил , программа продолжит выполняться, даже когда состояние программы могло бы быть неправильным.
Со вторым блоком, исключение будет брошено и пузыри , но эти reader.Close()
, как все еще гарантируют, будет работать.
, Если исключение не ожидается, то не помещайте попытку.. блок выгоды именно так, будет трудно отладить позже, когда программа вошла в плохое состояние, и у Вас нет идеи почему.
Apple абсолютно ясна по поводу этой темы:
Для изящное завершение работы iPhone заявление. В ОС iPhone пользователь нажимает кнопку «Домой», чтобы закрыть Приложения. Если ваше приложение иметь условия, в которых он не может обеспечить свое предназначение, рекомендуемый подход - отобразить alert for the user that indicates the nature of the problem and possible actions the user could take - turning on WiFi, enabling Location Services, etc. Allow the user to terminate the application at their own discretion.
I would advise you to reconsider for 3 reasons
If (for whatever reason)you do want to do it you can use.
exit(0);
You shouldn't do this. Take a look at "Stopping" in the Human Interface Guidelines as you could possibly fail for submitting an App that does this, or at the very least provide for a strange user experience.
The link also shows the correct way to handle this, as in the iTunes Music Store app.
Вы всегда можете просто разделить на ноль. В качестве бонуса реализация отразит, насколько это хорошая идея.
Your App will be rejected if you terminate when you cannot reach the Internet.
Sorry.
-t
You might consider informing the user that they cannot use your application without an active network connection. Just terminating the application outright seems like a very unfriendly way of doing this; the user will simply see the app "disappear".
Every well-behaved app I've seen will at least give a notification before terminating.
If you terminate it will look like your app has crashed!
Best to put up a message saying that there is no internet connection and give them an option to retry (in case they can get an internet connection), or choose to quite it themselves