Free cookie consent management tool by TermsFeed Policy Generator

source: stable/HeuristicLab.PluginInfrastructure/3.3/ErrorHandling/ErrorHandling.cs @ 11620

Last change on this file since 11620 was 11170, checked in by ascheibe, 10 years ago

#2115 updated copyright year in stable branch

File size: 2.7 KB
RevLine 
[3758]1#region License Information
2/* HeuristicLab
[11170]3 * Copyright (C) 2002-2014 Heuristic and Evolutionary Algorithms Laboratory (HEAL)
[3758]4 *
5 * This file is part of HeuristicLab.
6 *
7 * HeuristicLab is free software: you can redistribute it and/or modify
8 * it under the terms of the GNU General Public License as published by
9 * the Free Software Foundation, either version 3 of the License, or
10 * (at your option) any later version.
11 *
12 * HeuristicLab is distributed in the hope that it will be useful,
13 * but WITHOUT ANY WARRANTY; without even the implied warranty of
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
15 * GNU General Public License for more details.
16 *
17 * You should have received a copy of the GNU General Public License
18 * along with HeuristicLab. If not, see <http://www.gnu.org/licenses/>.
19 */
20#endregion
21
22using System;
23using System.Windows.Forms;
24
25namespace HeuristicLab.PluginInfrastructure {
26  public static class ErrorHandling {
27    public static string BuildErrorMessage(Exception exception) {
28      if (exception == null) {
29        return string.Empty;
30      } else {
[9339]31        string message =
[11121]32          "HeuristicLab version: " + AssemblyHelpers.GetFileVersion(typeof(ErrorHandling).Assembly) + Environment.NewLine +
[9339]33          exception.GetType().Name + ": " + exception.Message + Environment.NewLine +
[3758]34                         exception.StackTrace;
35
36        while (exception.InnerException != null) {
37          exception = exception.InnerException;
[5984]38          message += Environment.NewLine +
39                     "-----" + Environment.NewLine +
40                     exception.GetType().Name + ": " + exception.Message + Environment.NewLine +
[3758]41                     exception.StackTrace;
42        }
43        return message;
44      }
45    }
46
47    public static void ShowErrorDialog(Exception exception) {
48      ShowErrorDialog(string.Empty, exception);
49    }
50    public static void ShowErrorDialog(Control owner, Exception exception) {
51      ShowErrorDialog(owner, string.Empty, exception);
52    }
53    public static void ShowErrorDialog(string message, Exception exception) {
54      using (ErrorDialog dialog = new ErrorDialog(message, exception)) {
[5984]55        dialog.StartPosition = FormStartPosition.CenterScreen;
[3758]56        dialog.ShowDialog();
57      }
58    }
59    public static void ShowErrorDialog(Control owner, string message, Exception exception) {
[4482]60      if (owner == null) throw new ArgumentNullException("owner");
[3758]61      if (owner.InvokeRequired) {
62        owner.Invoke(new Action<Control, string, Exception>(ShowErrorDialog), owner, message, exception);
63      } else {
64        using (ErrorDialog dialog = new ErrorDialog(message, exception)) {
65          dialog.ShowDialog(owner);
66        }
67      }
68    }
69  }
70}
Note: See TracBrowser for help on using the repository browser.