Обработка ошибок

Loading...

Flash Player 9 (or above) is needed to view presentations.
We have detected that you do not have it on your computer. To install it, go here.

0 comments

Post a comment

    Post a comment
    Embed Video
    Edit your comment Cancel

    Favorites, Groups & Events

    Обработка ошибок - Presentation Transcript

    1. Обработка ошибок. Исключительные ситуации
    2. Лабораторная работа 2
      • 30 марта
      • Основной функционал
      • Пользовательский интерфейс с заглушками
      • Отчетность: Схемы классов, реализация, шаблоны
    3. Варианты обработки ошибок
      • Код возврата
      • Глобальная переменная
      • Прекращение выполнения программы
      • Возвращение специального объекта-результата
      • Исключительные ситуации
    4. Объект-результат
      • public XCalculatedCall CalculateAndProcess(XCallInformation a_Call)
      • {
      • XCalculationResult result = Calculate(a_Call);
      • if (!result.Success)
      • {
      • XBillingErrors.Instance.Register(a_Call, result.Error);
      • return null;
      • }
      • return result.CalculatedCall;
      • }
    5. Шаблоны
      • public int[] Find(string a_Needle)
      • {
      • if (string.IsNullOrEmpty(a_Needle))
      • {
      • throw new ArgumentNullException("Строка поиска не может быть пустой.");
      • }
      • List<int> result = new List<int>();
      • int startPosition = 0;
      • while(true)
      • {
      • int index = m_Haystack.IndexOf(a_Needle, startPosition);
      • if (index == -1)
      • {
      • break;
      • }
      • result.Add(index);
      • startPosition = index + 1;
      • }
      • return result.ToArray();
      • }
    6. Протоколирование
      • public void RegisterEvent(object a_Sender, Exception a_Excepton, EventType a_EventType)
      • {
      • string message = &quot;&quot;;
      • Exception exception = a_Excepton;
      • while (exception != null)
      • {
      • message += exception.Message + &quot; (&quot; + exception.GetType().FullName + &quot;) &quot; +
      • exception.StackTrace + &quot; &quot;;
      • exception = exception.InnerException;
      • }
      • RegisterEvent(a_Sender, a_Excepton.Message + &quot; (&quot; + a_Excepton.GetType().FullName + &quot;)&quot; , message, a_EventType);
      • }
    7. Минусы исключительных ситуаций
      • Позволяют выявить только одну ошибку (выход из алгоритма после первой ошибки)
      • Проверка производится только во время выполнения алгоритма
      • Могут снижать производительность
    8.  
    9. CheckResult
      • public static bool Test(XCheckResult a_Result)
      • {
      • return a_Result.IsSucceeded;
      • }
      • public static void Assert(XCheckResult a_Result)
      • {
      • if (a_Result.IsSucceeded)
      • {
      • return;
      • }
      • if (a_Result.Exception != null)
      • {
      • throw a_Result.Exception;
      • }
      • throw new ApplicationException(a_Result.Message);
      • }
      • public static XCheckResult Success()
      • {
      • return new XCheckResult(true, &quot;&quot;, null);
      • }
      • public static XCheckResult Fail(string a_Message)
      • {
      • return new XCheckResult(false, a_Message, null);
      • }
      • public static XCheckResult Fail(Exception a_Exception)
      • {
      • return new XCheckResult(false, a_Exception.Message, a_Exception);
      • }

    + kichikkichik, 5 months ago

    custom

    191 views, 0 favs, 2 embeds more stats

    Лекция Михаила Гуренкова по more

    More info about this document

    © All Rights Reserved

    Go to text version

    • Total Views 191
      • 158 on SlideShare
      • 33 from embeds
    • Comments 0
    • Favorites 0
    • Downloads 2
    Most viewed embeds
    • 25 views on http://oop.mainfo.ru
    • 8 views on http://www.oop.mainfo.ru

    more

    All embeds
    • 25 views on http://oop.mainfo.ru
    • 8 views on http://www.oop.mainfo.ru

    less

    Flagged as inappropriate Flag as inappropriate
    Flag as inappropriate

    Select your reason for flagging this presentation as inappropriate. If needed, use the feedback form to let us know more details.

    Cancel
    File a copyright complaint
    Having problems? Go to our helpdesk?

    Categories