Java SQLException exceptionToString(Throwable e)

Here you can find the source of exceptionToString(Throwable e)

Description

exception To String

License

Open Source License

Declaration

public static String exceptionToString(Throwable e) 

Method Source Code

//package com.java2s;
/*******************************************************************************
 * (c) Copyright 2017 Hewlett-Packard Development Company, L.P.
 * All rights reserved. This program and the accompanying materials
 * are made available under the terms of the Apache License v2.0 which accompany this distribution.
 *
 * The Apache License is available at//w w w . ja v a2s.com
 * http://www.apache.org/licenses/LICENSE-2.0
 *
 *******************************************************************************/

import java.io.*;
import java.sql.SQLException;

public class Main {
    public static String exceptionToString(Throwable e) {
        // Print the stack trace into an in memory string
        StringWriter writer = new StringWriter();
        e.printStackTrace(new java.io.PrintWriter(writer));

        // Process the stack trace, remove the FIRST null character
        return writer.toString().replace("" + (char) 0x00, "");
    }

    public static String toString(SQLException e) {
        String curr = exceptionToString(e) + "\nstate:" + e.getSQLState();
        while ((e = e.getNextException()) != null)
            curr += "\n\n" + exceptionToString(e) + "\nstate:" + e.getSQLState();
        return curr;
    }
}

Related

  1. appendToExceptionList(List list, SQLException sqlException)
  2. convertSQLExceptionToString(SQLException e)
  3. createFeatureNotSupportedException()
  4. exceptionMsg2LocalizedStr(final Throwable e)
  5. exceptionMsg2str(final Throwable e)
  6. extractErrorCode(SQLException sqlException)
  7. extractNestedSQLExceptions( SQLException exception)
  8. extractSqlStateClassCode(SQLException sqlException)
  9. getAllMessages(Throwable t, boolean includeExceptionName)