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