Source Code Cross Referenced for ExceptionUtil.java in  » Database-Client » SQL-Workbench » workbench » 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 » Database Client » SQL Workbench » workbench.util 
Source Cross Referenced  Class Diagram Java Document (Java Doc) 


001:        /*
002:         * ExceptionUtil.java
003:         *
004:         * This file is part of SQL Workbench/J, http://www.sql-workbench.net
005:         *
006:         * Copyright 2002-2008, Thomas Kellerer
007:         * No part of this code maybe reused without the permission of the author
008:         *
009:         * To contact the author please send an email to: support@sql-workbench.net
010:         *
011:         */
012:        package workbench.util;
013:
014:        import java.io.PrintWriter;
015:        import java.io.StringWriter;
016:        import java.sql.SQLException;
017:
018:        import workbench.log.LogMgr;
019:
020:        /**
021:         *
022:         *	@author  support@sql-workbench.net
023:         */
024:        public class ExceptionUtil {
025:
026:            private ExceptionUtil() {
027:            }
028:
029:            public static StringBuilder getSqlStateString(SQLException se) {
030:                StringBuilder result = new StringBuilder(30);
031:                try {
032:                    String state = se.getSQLState();
033:                    if (state != null && state.length() > 0) {
034:                        result.append("SQL State=");
035:                        result.append(state);
036:                    }
037:                    int error = se.getErrorCode();
038:                    if (error != 0) {
039:                        if (result.length() > 0)
040:                            result.append(", ");
041:                        result.append("DB Errorcode=");
042:                        result.append(Integer.toString(error));
043:                    }
044:                } catch (Throwable th) {
045:                    //result.append("(unknown)");
046:                }
047:                return result;
048:            }
049:
050:            public static StringBuilder getAllExceptions(Throwable th) {
051:                if (th instanceof  SQLException) {
052:                    return getAllExceptions((SQLException) th);
053:                }
054:                StringBuilder result = new StringBuilder(100);
055:                getDisplayBuffer(result, th, false);
056:                Throwable cause = th.getCause();
057:                while (cause != null) {
058:                    result.append("\nCaused by: ");
059:                    getDisplayBuffer(result, cause, false);
060:                    cause = cause.getCause();
061:                }
062:                return result;
063:            }
064:
065:            public static StringBuilder getAllExceptions(SQLException th) {
066:                StringBuilder result = new StringBuilder(100);
067:                getDisplayBuffer(result, th, false);
068:                SQLException next = th.getNextException();
069:                while (next != null) {
070:                    result.append("\nNext: ");
071:                    getDisplayBuffer(result, next, false);
072:                    next = next.getNextException();
073:                }
074:                return result;
075:            }
076:
077:            public static String getDisplay(Throwable th) {
078:                if (th instanceof  SQLException) {
079:                    return getAllExceptions((SQLException) th).toString();
080:                } else {
081:                    return getDisplay(th, false);
082:                }
083:            }
084:
085:            public static String getDisplay(Throwable th,
086:                    boolean includeStackTrace) {
087:                return getDisplayBuffer(null, th, includeStackTrace).toString();
088:            }
089:
090:            public static StringBuilder getDisplayBuffer(StringBuilder result,
091:                    Throwable th, boolean includeStackTrace) {
092:                if (result == null)
093:                    result = new StringBuilder(50);
094:                try {
095:                    if (th.getMessage() == null) {
096:                        result.append(th.getClass().getName());
097:                        if (!includeStackTrace) {
098:                            // always include Stacktrace for NPE
099:                            // sometimes these are not properly logged, and this way
100:                            // the stacktrace does at least show up in the front end
101:                            // which should not happen anyway, but if it does, 
102:                            // we have at least proper error information
103:                            includeStackTrace = (th instanceof  NullPointerException);
104:                        }
105:                    } else {
106:                        result.append(th.getMessage().trim());
107:                    }
108:
109:                    if (th instanceof  SQLException) {
110:                        SQLException se = (SQLException) th;
111:                        StringBuilder state = getSqlStateString(se);
112:                        if (state.length() > 0) {
113:                            result.append(" [");
114:                            result.append(state);
115:                            result.append("] ");
116:                        }
117:                    }
118:
119:                    if (includeStackTrace) {
120:                        StringWriter sw = new StringWriter();
121:                        PrintWriter pw = new PrintWriter(sw);
122:                        th.printStackTrace(pw);
123:                        result.append("\r\n");
124:                        result.append(sw.getBuffer());
125:                    }
126:                } catch (Throwable th1) {
127:                    LogMgr.logError("ExceptionUtil.getDisplay()",
128:                            "Error while creating display string", th1);
129:                    result.append("Exception: " + th.getClass().getName());
130:                }
131:                return result;
132:            }
133:
134:        }
www.java2java.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.