[2] | 1 | #region License Information
|
---|
| 2 | /* HeuristicLab
|
---|
[2790] | 3 | * Copyright (C) 2002-2010 Heuristic and Evolutionary Algorithms Laboratory (HEAL)
|
---|
[2] | 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.Text;
|
---|
| 24 | using System.Windows.Forms;
|
---|
| 25 |
|
---|
[2520] | 26 | namespace HeuristicLab.Core.Views {
|
---|
[776] | 27 | /// <summary>
|
---|
| 28 | /// Static helper class.
|
---|
| 29 | /// </summary>
|
---|
[2] | 30 | public static class Auxiliary {
|
---|
| 31 | #region Error Messages
|
---|
[776] | 32 | /// <summary>
|
---|
| 33 | /// Shows an error message box with a given error <paramref name="message"/> and an OK-Button.
|
---|
| 34 | /// </summary>
|
---|
| 35 | /// <param name="message">The error message to display.</param>
|
---|
[2] | 36 | public static void ShowErrorMessageBox(string message) {
|
---|
| 37 | MessageBox.Show(message,
|
---|
| 38 | "Error",
|
---|
| 39 | MessageBoxButtons.OK,
|
---|
| 40 | MessageBoxIcon.Error);
|
---|
| 41 | }
|
---|
[776] | 42 | /// <summary>
|
---|
| 43 | /// Shows an error message box with a given exception <paramref name="ex"/> and an OK-Button.
|
---|
| 44 | /// </summary>
|
---|
| 45 | /// <param name="ex">The exception to display.</param>
|
---|
[2] | 46 | public static void ShowErrorMessageBox(Exception ex) {
|
---|
| 47 | MessageBox.Show(BuildErrorMessage(ex),
|
---|
| 48 | "Error - " + ex.GetType().Name,
|
---|
| 49 | MessageBoxButtons.OK,
|
---|
| 50 | MessageBoxIcon.Error);
|
---|
| 51 | }
|
---|
[776] | 52 | /// <summary>
|
---|
| 53 | /// Builds an error message out of an exception and formats it accordingly.
|
---|
| 54 | /// </summary>
|
---|
| 55 | /// <param name="ex">The exception to format.</param>
|
---|
| 56 | /// <returns>The formated message.</returns>
|
---|
[2916] | 57 | public static string BuildErrorMessage(Exception ex) {
|
---|
| 58 | string nl = Environment.NewLine;
|
---|
[2] | 59 | StringBuilder sb = new StringBuilder();
|
---|
[2916] | 60 | sb.Append("Sorry, but something went wrong!" + nl + ex.Message + nl + ex.StackTrace);
|
---|
[2] | 61 |
|
---|
| 62 | while (ex.InnerException != null) {
|
---|
| 63 | ex = ex.InnerException;
|
---|
[2916] | 64 | sb.Append(nl + "-----" + nl + ex.Message + nl + ex.StackTrace);
|
---|
[2] | 65 | }
|
---|
| 66 | return sb.ToString();
|
---|
| 67 | }
|
---|
| 68 | #endregion
|
---|
| 69 | }
|
---|
| 70 | }
|
---|