KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > eclipse > ui > internal > ExceptionHandler


1 /*******************************************************************************
2  * Copyright (c) 2000, 2006 IBM Corporation and others.
3  * All rights reserved. This program and the accompanying materials
4  * are made available under the terms of the Eclipse Public License v1.0
5  * which accompanies this distribution, and is available at
6  * http://www.eclipse.org/legal/epl-v10.html
7  *
8  * Contributors:
9  * IBM Corporation - initial API and implementation
10  *******************************************************************************/

11 package org.eclipse.ui.internal;
12
13 import org.eclipse.jface.window.Window;
14
15 /**
16  * This handler will pass along to the workbench advisor exceptions
17  * and errors thrown while running the event loop. However, the
18  * <code>ThreadDeath</code> error is simply thrown again, and is not
19  * passed along.
20  */

21 public final class ExceptionHandler implements Window.IExceptionHandler {
22
23     private static final ExceptionHandler instance = new ExceptionHandler();
24
25     /**
26      * Returns the singleton exception handler.
27      *
28      * @return the singleton exception handler
29      */

30     public static ExceptionHandler getInstance() {
31         return instance;
32     }
33
34     private int exceptionCount = 0; // To avoid recursive errors
35

36     private ExceptionHandler() {
37         // prevents instantiation
38
}
39
40     /* (non-javadoc)
41      * @see org.eclipse.jface.window.Window.IExceptionHandler#handleException
42      */

43     public void handleException(Throwable JavaDoc t) {
44         try {
45             // Ignore ThreadDeath error as its normal to get this when thread dies
46
if (t instanceof ThreadDeath JavaDoc) {
47                 throw (ThreadDeath JavaDoc) t;
48             }
49
50             // Check to avoid recursive errors
51
exceptionCount++;
52             if (exceptionCount > 2) {
53                 if (t instanceof RuntimeException JavaDoc) {
54                     throw (RuntimeException JavaDoc) t;
55                 }
56                 throw (Error JavaDoc) t;
57             }
58
59             // Let the advisor handle this now
60
Workbench wb = Workbench.getInstance();
61             if (wb != null) {
62                 wb.getAdvisor().eventLoopException(t);
63             }
64         } finally {
65             exceptionCount--;
66         }
67     }
68 }
69
Popular Tags