Source Code Cross Referenced for ExceptionHandler.java in  » IDE-Eclipse » jdt » org » eclipse » jdt » internal » ui » util » Java Source Code / Java DocumentationJava Source Code and Java Documentation

Java Source Code / Java Documentation
1. 6.0 JDK Core
2. 6.0 JDK Modules
3. 6.0 JDK Modules com.sun
4. 6.0 JDK Modules com.sun.java
5. 6.0 JDK Modules sun
6. 6.0 JDK Platform
7. Ajax
8. Apache Harmony Java SE
9. Aspect oriented
10. Authentication Authorization
11. Blogger System
12. Build
13. Byte Code
14. Cache
15. Chart
16. Chat
17. Code Analyzer
18. Collaboration
19. Content Management System
20. Database Client
21. Database DBMS
22. Database JDBC Connection Pool
23. Database ORM
24. Development
25. EJB Server geronimo
26. EJB Server GlassFish
27. EJB Server JBoss 4.2.1
28. EJB Server resin 3.1.5
29. ERP CRM Financial
30. ESB
31. Forum
32. GIS
33. Graphic Library
34. Groupware
35. HTML Parser
36. IDE
37. IDE Eclipse
38. IDE Netbeans
39. Installer
40. Internationalization Localization
41. Inversion of Control
42. Issue Tracking
43. J2EE
44. JBoss
45. JMS
46. JMX
47. Library
48. Mail Clients
49. Net
50. Parser
51. PDF
52. Portal
53. Profiler
54. Project Management
55. Report
56. RSS RDF
57. Rule Engine
58. Science
59. Scripting
60. Search Engine
61. Security
62. Sevlet Container
63. Source Control
64. Swing Library
65. Template Engine
66. Test Coverage
67. Testing
68. UML
69. Web Crawler
70. Web Framework
71. Web Mail
72. Web Server
73. Web Services
74. Web Services apache cxf 2.0.1
75. Web Services AXIS2
76. Wiki Engine
77. Workflow Engines
78. XML
79. XML UI
Java
Java Tutorial
Java Open Source
Jar File Download
Java Articles
Java Products
Java by API
Photoshop Tutorials
Maya Tutorials
Flash Tutorials
3ds-Max Tutorials
Illustrator Tutorials
GIMP Tutorials
C# / C Sharp
C# / CSharp Tutorial
C# / CSharp Open Source
ASP.Net
ASP.NET Tutorial
JavaScript DHTML
JavaScript Tutorial
JavaScript Reference
HTML / CSS
HTML CSS Reference
C / ANSI-C
C Tutorial
C++
C++ Tutorial
Ruby
PHP
Python
Python Tutorial
Python Open Source
SQL Server / T-SQL
SQL Server / T-SQL Tutorial
Oracle PL / SQL
Oracle PL/SQL Tutorial
PostgreSQL
SQL / MySQL
MySQL Tutorial
VB.Net
VB.Net Tutorial
Flash / Flex / ActionScript
VBA / Excel / Access / Word
XML
XML Tutorial
Microsoft Office PowerPoint 2007 Tutorial
Microsoft Office Excel 2007 Tutorial
Microsoft Office Word 2007 Tutorial
Java Source Code / Java Documentation » IDE Eclipse » jdt » org.eclipse.jdt.internal.ui.util 
Source Cross Referenced  Class Diagram Java Document (Java Doc) 


001:        /*******************************************************************************
002:         * Copyright (c) 2000, 2005 IBM Corporation and others.
003:         * All rights reserved. This program and the accompanying materials
004:         * are made available under the terms of the Eclipse Public License v1.0
005:         * which accompanies this distribution, and is available at
006:         * http://www.eclipse.org/legal/epl-v10.html
007:         *
008:         * Contributors:
009:         *     IBM Corporation - initial API and implementation
010:         *******************************************************************************/package org.eclipse.jdt.internal.ui.util;
011:
012:        import java.io.StringWriter;
013:        import java.lang.reflect.InvocationTargetException;
014:
015:        import org.eclipse.swt.widgets.Shell;
016:
017:        import org.eclipse.core.runtime.CoreException;
018:        import org.eclipse.core.runtime.IStatus;
019:        import org.eclipse.core.runtime.Status;
020:
021:        import org.eclipse.jdt.internal.ui.JavaPlugin;
022:        import org.eclipse.jdt.internal.ui.IJavaStatusConstants;
023:        import org.eclipse.jdt.internal.ui.JavaUIMessages;
024:        import org.eclipse.jface.dialogs.ErrorDialog;
025:        import org.eclipse.jface.dialogs.MessageDialog;
026:
027:        /**
028:         * The default exception handler shows an error dialog when one of its handle methods
029:         * is called. If the passed exception is a <code>CoreException</code> an error dialog
030:         * pops up showing the exception's status information. For a <code>InvocationTargetException</code>
031:         * a normal message dialog pops up showing the exception's message. Additionally the exception
032:         * is written to the platform log.
033:         */
034:        public class ExceptionHandler {
035:
036:            private static ExceptionHandler fgInstance = new ExceptionHandler();
037:
038:            /**
039:             * Logs the given exception using the platform's logging mechanism. The exception is
040:             * logged as an error with the error code <code>JavaStatusConstants.INTERNAL_ERROR</code>.
041:             */
042:            public static void log(Throwable t, String message) {
043:                JavaPlugin.log(new Status(IStatus.ERROR, JavaPlugin
044:                        .getPluginId(), IJavaStatusConstants.INTERNAL_ERROR,
045:                        message, t));
046:            }
047:
048:            /**
049:             * Handles the given <code>CoreException</code>. The workbench shell is used as a parent
050:             * for the dialog window.
051:             * 
052:             * @param e the <code>CoreException</code> to be handled
053:             * @param title the dialog window's window title
054:             * @param message message to be displayed by the dialog window
055:             */
056:            public static void handle(CoreException e, String title,
057:                    String message) {
058:                handle(e, JavaPlugin.getActiveWorkbenchShell(), title, message);
059:            }
060:
061:            /**
062:             * Handles the given <code>CoreException</code>. 
063:             * 
064:             * @param e the <code>CoreException</code> to be handled
065:             * @param parent the dialog window's parent shell
066:             * @param title the dialog window's window title
067:             * @param message message to be displayed by the dialog window
068:             */
069:            public static void handle(CoreException e, Shell parent,
070:                    String title, String message) {
071:                fgInstance.perform(e, parent, title, message);
072:            }
073:
074:            /**
075:             * Handles the given <code>InvocationTargetException</code>. The workbench shell is used 
076:             * as a parent for the dialog window.
077:             * 
078:             * @param e the <code>InvocationTargetException</code> to be handled
079:             * @param title the dialog window's window title
080:             * @param message message to be displayed by the dialog window
081:             */
082:            public static void handle(InvocationTargetException e,
083:                    String title, String message) {
084:                handle(e, JavaPlugin.getActiveWorkbenchShell(), title, message);
085:            }
086:
087:            /**
088:             * Handles the given <code>InvocationTargetException</code>. 
089:             * 
090:             * @param e the <code>InvocationTargetException</code> to be handled
091:             * @param parent the dialog window's parent shell
092:             * @param title the dialog window's window title
093:             * @param message message to be displayed by the dialog window
094:             */
095:            public static void handle(InvocationTargetException e,
096:                    Shell parent, String title, String message) {
097:                fgInstance.perform(e, parent, title, message);
098:            }
099:
100:            //---- Hooks for subclasses to control exception handling ------------------------------------
101:
102:            protected void perform(CoreException e, Shell shell, String title,
103:                    String message) {
104:                JavaPlugin.log(e);
105:                IStatus status = e.getStatus();
106:                if (status != null) {
107:                    ErrorDialog.openError(shell, title, message, status);
108:                } else {
109:                    displayMessageDialog(e, e.getMessage(), shell, title,
110:                            message);
111:                }
112:            }
113:
114:            protected void perform(InvocationTargetException e, Shell shell,
115:                    String title, String message) {
116:                Throwable target = e.getTargetException();
117:                if (target instanceof  CoreException) {
118:                    perform((CoreException) target, shell, title, message);
119:                } else {
120:                    JavaPlugin.log(e);
121:                    if (e.getMessage() != null && e.getMessage().length() > 0) {
122:                        displayMessageDialog(e, e.getMessage(), shell, title,
123:                                message);
124:                    } else {
125:                        displayMessageDialog(e, target.getMessage(), shell,
126:                                title, message);
127:                    }
128:                }
129:            }
130:
131:            //---- Helper methods -----------------------------------------------------------------------
132:
133:            private void displayMessageDialog(Throwable t,
134:                    String exceptionMessage, Shell shell, String title,
135:                    String message) {
136:                StringWriter msg = new StringWriter();
137:                if (message != null) {
138:                    msg.write(message);
139:                    msg.write("\n\n"); //$NON-NLS-1$
140:                }
141:                if (exceptionMessage == null || exceptionMessage.length() == 0)
142:                    msg
143:                            .write(JavaUIMessages.ExceptionDialog_seeErrorLogMessage);
144:                else
145:                    msg.write(exceptionMessage);
146:                MessageDialog.openError(shell, title, msg.toString());
147:            }
148:        }
www.java2java.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.