1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18 package org.apache.any23.extractor;
19
20 import java.io.OutputStreamWriter;
21 import java.io.PrintStream;
22 import java.io.PrintWriter;
23 import java.nio.charset.StandardCharsets;
24
25
26
27
28
29
30 public class ExtractionException extends Exception {
31
32 private ExtractionResult extractionResult;
33
34 public ExtractionException(String message) {
35 super(message);
36 }
37
38 public ExtractionException(String message, Throwable cause) {
39 super(message, cause);
40 }
41
42 public ExtractionException(String message, Throwable cause, ExtractionResult er) {
43 super(message, cause);
44 extractionResult = er;
45 }
46
47 @Override
48 public void printStackTrace(PrintStream ps) {
49 printExceptionResult(new PrintWriter(new OutputStreamWriter(ps, StandardCharsets.UTF_8), true));
50 super.printStackTrace(ps);
51 }
52
53 @Override
54 public void printStackTrace(PrintWriter pw) {
55 printExceptionResult(pw);
56 super.printStackTrace(pw);
57 }
58
59 private void printExceptionResult(PrintWriter ps) {
60 if (extractionResult == null) {
61 return;
62 }
63 ps.println();
64 ps.println("------------ BEGIN Exception context ------------");
65 ps.print(extractionResult.toString());
66 ps.println("------------ END Exception context ------------");
67 ps.println();
68 ps.flush();
69 }
70 }