1 package com.explosion.utilities.exception;
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23 import java.util.Vector;
24
25 /***
26 * @author Stephen Cowx
27 * @version 1.0
28 */
29
30 public class ExceptionManager
31 {
32
33 private Vector exceptionHandlers = new Vector();
34
35 private DefaultExceptionHandler defaultHandler;
36
37 /***
38 * Method addExceptionHandler. Adds an ExceptionHandler to the manager. All
39 * exceptions managed by this manager willbe passedto this exception
40 * handler.
41 *
42 * @param handler
43 */
44 public void addExceptionHandler(ExceptionHandler handler)
45 {
46 exceptionHandlers.addElement(handler);
47 }
48
49 /***
50 * Method removeExceptionHandler. Removes an exceptionHandler from this
51 * manager.
52 *
53 * @param handler
54 */
55 public void removeExceptionHandler(ExceptionHandler handler)
56 {
57 exceptionHandlers.remove(handler);
58 }
59
60 /***
61 * Method manageException. Distributes this exception to all of the
62 * registered ExceptionHandlers. If there are none itwilluse
63 * defaultExceptionHandler. It is usually not mandatory that the Frame is
64 * not null.
65 *
66 * @param e
67 * @param message
68 * @param owner
69 */
70 public void manageException(Throwable e, String message)
71 {
72 if (exceptionHandlers.size() < 1 )
73 {
74 if (defaultHandler == null)
75 {
76 defaultHandler = new DefaultExceptionHandler();
77 }
78 defaultHandler.handleException(e, message);
79 }
80 else
81 {
82 for (int i = 0; i < exceptionHandlers.size(); i++)
83 {
84 ((ExceptionHandler) exceptionHandlers.elementAt(i)).handleException(e, message);
85 }
86 }
87 }
88 }