/*
 * Copyright (c) 2002-2010 JSCAPE
 * 1147 S. 53rd Pl., Mesa, Arizona, 85206, U.S.A.
 * All rights reserved.
 *
 * This software is the confidential and proprietary information of
 * JSCAPE. ("Confidential Information").  You shall not disclose such
 * Confidential Information and shall use it only in accordance with
 *  the terms of the license agreement you entered into with JSCAPE.
 */

package com.jscape.util;

import java.io.IOException;
import java.io.PrintWriter;
import java.io.StringWriter;

/**
 * @author Alex Usun
 */
public class ExceptionTools {

    public static String stackTraceOf(Throwable e) {
        StringWriter buf = new StringWriter();
        e.printStackTrace(new PrintWriter(buf));
        return buf.toString();
    }

    public static IOException ioException(Throwable e) {
        return e instanceof IOException ? (IOException) e : new IOException(messageOf(e), e);
    }

    public static String messageOf(Throwable e) {
        return e.getMessage() != null ? e.getMessage() : e.toString();
    }

    private ExceptionTools() {
        // empty
    }
}
