1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17 package org.yaml.snakeyaml.error;
18
19 public class MarkedYAMLException extends YAMLException {
20
21 private static final long serialVersionUID = -9119388488683035101L;
22 private String context;
23 private Mark contextMark;
24 private String problem;
25 private Mark problemMark;
26 private String note;
27
28 protected MarkedYAMLException(String context, Mark contextMark, String problem,
29 Mark problemMark, String note) {
30 this(context, contextMark, problem, problemMark, note, null);
31 }
32
33 protected MarkedYAMLException(String context, Mark contextMark, String problem,
34 Mark problemMark, String note, Throwable cause) {
35 super(context + "; " + problem, cause);
36 this.context = context;
37 this.contextMark = contextMark;
38 this.problem = problem;
39 this.problemMark = problemMark;
40 this.note = note;
41 }
42
43 protected MarkedYAMLException(String context, Mark contextMark, String problem, Mark problemMark) {
44 this(context, contextMark, problem, problemMark, null, null);
45 }
46
47 protected MarkedYAMLException(String context, Mark contextMark, String problem,
48 Mark problemMark, Throwable cause) {
49 this(context, contextMark, problem, problemMark, null, cause);
50 }
51
52 @Override
53 public String toString() {
54 StringBuilder lines = new StringBuilder();
55 if (context != null) {
56 lines.append(context);
57 lines.append("\n");
58 }
59 if (contextMark != null
60 && (problem == null || problemMark == null
61 || (contextMark.getName() != problemMark.getName())
62 || (contextMark.getLine() != problemMark.getLine()) || (contextMark
63 .getColumn() != problemMark.getColumn()))) {
64 lines.append(contextMark.toString());
65 lines.append("\n");
66 }
67 if (problem != null) {
68 lines.append(problem);
69 lines.append("\n");
70 }
71 if (problemMark != null) {
72 lines.append(problemMark.toString());
73 lines.append("\n");
74 }
75 if (note != null) {
76 lines.append(note);
77 lines.append("\n");
78 }
79 return lines.toString();
80 }
81
82 public String getContext() {
83 return context;
84 }
85
86 public Mark getContextMark() {
87 return contextMark;
88 }
89
90 public String getProblem() {
91 return problem;
92 }
93
94 public Mark getProblemMark() {
95 return problemMark;
96 }
97 }