1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92 | package Torello.HTML.Tools.NewsSite;
import java.io.IOException;
import Torello.HTML.HTMLPageMWT;
import Torello.HTML.Tools.NewsSite.DownloadResult;
import Torello.HTML.Tools.NewsSite.RECORD;
import Torello.Java.EXCC;
class HandleExceptions
{
static void receiverException(final RECORD r, final ReceiveException re)
throws ReceiveException, IOException // The Appendable's `append` method
{
// NOTE: If there was a "ReceiveException" then article-downloading must be
// halted immediately. A ReceiveException implies that the user did not
// properly handle the downloaded Article, and the user's code would have
// to be debugged.
r.log.append(
"There was an error when attempting to pass the downloaded article to " +
"the ArticleReceiver. Unrecoverable. Saving download state, and " +
"halting download.\n"
);
// Make sure to save the internal download state
if (r.pause != null)
r.pause.saveState
(r.ret, r.outerCounter(), r.innerCounter(), r.successCounter());
// Make sure to stop the download process now. If the article "Receiver"
// failed to save or store a received-article, there is NO POINT IN CONTINUING
// THE DOWNLOADER.
//
// NOTE: This will cause the method to exit with error, make sure to stop the
// "MWT Thread" Remember, this is just a simple "Monitor Thread" that
// prevents a download from hanging.
HTMLPageMWT.shutdownMWTThreads();
throw re;
}
static void ioException(final RECORD r, final IOException ioe) throws IOException
{
// This exception occurs if writing the "Appendable" (the log) fails. If this
// happens, download should halt immediately, and the internal-state should be
// saved to the 'pause' variable.
if (r.pause != null)
r.pause.saveState
(r.ret, r.outerCounter(), r.innerCounter(), r.successCounter());
// Need to stop the download process. IOException could ONLY BE the result of
// the "Appendable.append" method. None of the other stuff throws IOException.
//
// ALSO: If the "Appendable" never fails (which is 99% likely not to happen),
// This catch-statement will never actually execute. However, if
// the Appendable did, in fact, fail to write - then downloading cannot
// continue
//
// NOTE: This will cause the method to exit with error, make sure to stop the
// HTMLPage's "MWT Thread" (It is a simple "Monitor Thread") that
// can be used to prevent the download from hanging.
// HOWEVER, it will also cause the JVM to 'hang' this thread exits
// without shutting down the monitor-thread!
HTMLPageMWT.shutdownMWTThreads();
throw ioe;
}
static void exception(final RECORD r, final Exception e) throws IOException
{
// *** *** *** *** *** *** *** *** *** *** *** *** *** *** *** *** *** *** *** *** *** ***
// Handle "Unknown Exception" case.
// *** *** *** *** *** *** *** *** *** *** *** *** *** *** *** *** *** *** *** *** *** ***
r.log.append(
"There was an unknown Exception:\n" + EXCC.toString(e) +
"\nSkipping URL: " + r.url + '\n'
);
r.ret
.elementAt(r.outerCounter())
.add(DownloadResult.UNKNOWN_EXCEPTION);
}
}
|