1 /* This file is part of the project "Hilbert II" - http://www.qedeq.org" target="alexandria_uri">http://www.qedeq.org
2 *
3 * Copyright 2000-2014, Michael Meyling <mime@qedeq.org>.
4 *
5 * "Hilbert II" is free software; you can redistribute
6 * it and/or modify it under the terms of the GNU General Public
7 * License as published by the Free Software Foundation; either
8 * version 2 of the License, or (at your option) any later version.
9 *
10 * This program is distributed in the hope that it will be useful,
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 * GNU General Public License for more details.
14 */
15
16 package org.qedeq.kernel.bo.logic.common;
17
18 import org.qedeq.kernel.se.base.list.Element;
19 import org.qedeq.kernel.se.common.ModuleContext;
20 import org.qedeq.kernel.se.common.ModuleDataException;
21
22 /**
23 * This is the basis for an exception for logical errors within a QEDEQ module.
24 *
25 * @author Michael Meyling
26 */
27 public abstract class LogicalCheckException extends ModuleDataException {
28
29 /**
30 * This element causes the error.
31 */
32 private final Element element;
33
34 /**
35 * Constructs an exception.
36 *
37 * @param errorCode ErrorCode of this message.
38 * @param message What is the problem.
39 * @param element Problematic line.
40 * @param context Error location.
41 * @param referenceContext Reference location.
42 */
43 public LogicalCheckException(final int errorCode, final String message, final Element element,
44 final ModuleContext context, final ModuleContext referenceContext) {
45 super(errorCode, message, context, referenceContext);
46 this.element = element;
47 }
48
49 /**
50 * Constructs an exception.
51 *
52 * @param errorCode ErrorCode of this message.
53 * @param message What is the problem.
54 * @param element Problematic formula.
55 * @param context Error location.
56 */
57 public LogicalCheckException(final int errorCode, final String message,
58 final Element element, final ModuleContext context) {
59 super(errorCode, message, context);
60 this.element = element;
61 }
62
63 /**
64 * Constructs an exception.
65 *
66 * @param errorCode ErrorCode of this message.
67 * @param message What is the problem.
68 * @param context Error location.
69 */
70 public LogicalCheckException(final int errorCode, final String message,
71 final ModuleContext context) {
72 super(errorCode, message, context);
73 this.element = null;
74 }
75
76 /**
77 * Get the problematic element. Might be <code>null</code>.
78 *
79 * @return Element.
80 */
81 public final Element getElement() {
82 return this.element;
83 }
84
85 /**
86 * Returns a short description of this throwable.
87 * If this <code>Throwable</code> object was created with a non-null detail
88 * message string, then the result is the concatenation of five strings:
89 * <ul>
90 * <li>The name of the actual class of this object
91 * <li>": " (a colon and a space)
92 * <li>The result of the {@link Throwable#getMessage()} method for this object
93 * <li>"\n" (a newline)
94 * <li>A string representation of the {@link #getElement()} method for this object
95 * (might be empty).
96 * </ul>
97 *
98 * @return a string representation of this throwable.
99 */
100 public final String toString() {
101 return super.toString() + "\n"
102 + (getElement() != null ? getElement().toString() : "");
103 }
104
105 }