Java SQLException to String toString(Throwable x)

Here you can find the source of toString(Throwable x)

Description

Convert x to a String by calling its toString method.

License

Open Source License

Declaration

public static String toString(Throwable x) 

Method Source Code

//package com.java2s;
/*//  ww w  . j a v  a2s  . c  o m
 * Copyright (c) 1998 - 2005 Versant Corporation
 * All rights reserved. This program and the accompanying materials
 * are made available under the terms of the Eclipse Public License v1.0
 * which accompanies this distribution, and is available at
 * http://www.eclipse.org/legal/epl-v10.html
 *
 * Contributors:
 * Versant Corporation - initial API and implementation
 */

import java.sql.SQLException;

public class Main {
    /**
     * Convert x to a String by calling its toString method. If x is an
     * SQLException then any getNextExceptions() are recursively added to
     * the string preceded by linefeeds.
     */
    public static String toString(Throwable x) {
        if (x instanceof SQLException) {
            StringBuffer s = new StringBuffer();
            s.append(x);
            SQLException se = (SQLException) x;
            for (se = se.getNextException(); se != null; se = se.getNextException()) {
                s.append('\n');
                s.append(se);
                int n = s.length() - 1;
                if (s.charAt(n) == '\n')
                    s.setLength(n);
            }
            return s.toString();
        } else {
            return x.toString();
        }
    }
}

Related

  1. toString(SQLException e)