[3758] | 1 | #region License Information
|
---|
| 2 | /* HeuristicLab
|
---|
[7268] | 3 | * Copyright (C) 2002-2012 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 |
|
---|
| 22 | using System;
|
---|
| 23 | using System.Windows.Forms;
|
---|
| 24 |
|
---|
| 25 | namespace HeuristicLab.PluginInfrastructure {
|
---|
| 26 | public static class ErrorHandling {
|
---|
| 27 | public static string BuildErrorMessage(Exception exception) {
|
---|
| 28 | if (exception == null) {
|
---|
| 29 | return string.Empty;
|
---|
| 30 | } else {
|
---|
[5984] | 31 | string message = exception.GetType().Name + ": " + exception.Message + Environment.NewLine +
|
---|
[3758] | 32 | exception.StackTrace;
|
---|
| 33 |
|
---|
| 34 | while (exception.InnerException != null) {
|
---|
| 35 | exception = exception.InnerException;
|
---|
[5984] | 36 | message += Environment.NewLine +
|
---|
| 37 | "-----" + Environment.NewLine +
|
---|
| 38 | exception.GetType().Name + ": " + exception.Message + Environment.NewLine +
|
---|
[3758] | 39 | exception.StackTrace;
|
---|
| 40 | }
|
---|
| 41 | return message;
|
---|
| 42 | }
|
---|
| 43 | }
|
---|
| 44 |
|
---|
| 45 | public static void ShowErrorDialog(Exception exception) {
|
---|
| 46 | ShowErrorDialog(string.Empty, exception);
|
---|
| 47 | }
|
---|
| 48 | public static void ShowErrorDialog(Control owner, Exception exception) {
|
---|
| 49 | ShowErrorDialog(owner, string.Empty, exception);
|
---|
| 50 | }
|
---|
| 51 | public static void ShowErrorDialog(string message, Exception exception) {
|
---|
| 52 | using (ErrorDialog dialog = new ErrorDialog(message, exception)) {
|
---|
[5984] | 53 | dialog.StartPosition = FormStartPosition.CenterScreen;
|
---|
[3758] | 54 | dialog.ShowDialog();
|
---|
| 55 | }
|
---|
| 56 | }
|
---|
| 57 | public static void ShowErrorDialog(Control owner, string message, Exception exception) {
|
---|
[4482] | 58 | if (owner == null) throw new ArgumentNullException("owner");
|
---|
[3758] | 59 | if (owner.InvokeRequired) {
|
---|
| 60 | owner.Invoke(new Action<Control, string, Exception>(ShowErrorDialog), owner, message, exception);
|
---|
| 61 | } else {
|
---|
| 62 | using (ErrorDialog dialog = new ErrorDialog(message, exception)) {
|
---|
| 63 | dialog.ShowDialog(owner);
|
---|
| 64 | }
|
---|
| 65 | }
|
---|
| 66 | }
|
---|
| 67 | }
|
---|
| 68 | }
|
---|