01: /*******************************************************************************
02: * Copyright (c) 2000, 2006 IBM Corporation and others.
03: * All rights reserved. This program and the accompanying materials
04: * are made available under the terms of the Eclipse Public License v1.0
05: * which accompanies this distribution, and is available at
06: * http://www.eclipse.org/legal/epl-v10.html
07: *
08: * Contributors:
09: * IBM Corporation - initial API and implementation
10: *******************************************************************************/package org.eclipse.ui.internal;
11:
12: import org.eclipse.jface.window.Window;
13:
14: /**
15: * This handler will pass along to the workbench advisor exceptions
16: * and errors thrown while running the event loop. However, the
17: * <code>ThreadDeath</code> error is simply thrown again, and is not
18: * passed along.
19: */
20: public final class ExceptionHandler implements Window.IExceptionHandler {
21:
22: private static final ExceptionHandler instance = new ExceptionHandler();
23:
24: /**
25: * Returns the singleton exception handler.
26: *
27: * @return the singleton exception handler
28: */
29: public static ExceptionHandler getInstance() {
30: return instance;
31: }
32:
33: private int exceptionCount = 0; // To avoid recursive errors
34:
35: private ExceptionHandler() {
36: // prevents instantiation
37: }
38:
39: /* (non-javadoc)
40: * @see org.eclipse.jface.window.Window.IExceptionHandler#handleException
41: */
42: public void handleException(Throwable t) {
43: try {
44: // Ignore ThreadDeath error as its normal to get this when thread dies
45: if (t instanceof ThreadDeath) {
46: throw (ThreadDeath) t;
47: }
48:
49: // Check to avoid recursive errors
50: exceptionCount++;
51: if (exceptionCount > 2) {
52: if (t instanceof RuntimeException) {
53: throw (RuntimeException) t;
54: }
55: throw (Error) t;
56: }
57:
58: // Let the advisor handle this now
59: Workbench wb = Workbench.getInstance();
60: if (wb != null) {
61: wb.getAdvisor().eventLoopException(t);
62: }
63: } finally {
64: exceptionCount--;
65: }
66: }
67: }
|