Example usage for java.lang Throwable printStackTrace

List of usage examples for java.lang Throwable printStackTrace

Introduction

In this page you can find the example usage for java.lang Throwable printStackTrace.

Prototype

public void printStackTrace() 

Source Link

Document

Prints this throwable and its backtrace to the standard error stream.

Usage

From source file:icehx.openiab.OpenIAB.java

public static void _createService(final HaxeObject callback, int verifyMode, boolean debugLog,
        String[] preferredStoreNames, boolean checkInventory, String[] availableStoreNames,
        int storeSearchStrategy) {
    try {/*from   w  ww . j  a  v  a  2  s  . c  o  m*/
        OpenIAB.debugLog = debugLog;
        if (mHelper != null) {
            Log_w("Service already started");
        }

        // Clear inventory
        OpenIAB.inventory = new Inventory();
        OpenIAB.callback = callback;

        // enable debug logging (for a production application, you should set this to false).
        Logger.setLoggable(debugLog);

        // Create the helper, passing it our context and the public key to verify signatures with
        Log_d("Creating IAB helper.");
        //Only map SKUs for stores that using purchase with SKUs different from described in store console.
        OpenIabHelper.Options.Builder builder = new OpenIabHelper.Options.Builder();
        builder.setCheckInventory(checkInventory);
        builder.setVerifyMode(verifyMode);
        builder.addStoreKeys(STORE_KEYS_MAP);
        if (preferredStoreNames != null && preferredStoreNames.length > 0) {
            builder.addPreferredStoreName(preferredStoreNames);
        }
        if (availableStoreNames != null && availableStoreNames.length > 0) {
            builder.addAvailableStoreNames(availableStoreNames);
        }
        builder.setStoreSearchStrategy(storeSearchStrategy);

        mHelper = new OpenIabHelper(mainContext, builder.build());

        // Start setup. This is asynchronous and the specified listener
        // will be called once setup completes.
        Log_d("Starting setup.");
        mHelper.startSetup(new IabHelper.OnIabSetupFinishedListener() {
            public void onIabSetupFinished(IabResult result) {
                Log_d("Setup finished.");
                if (result.isSuccess()) {
                    // Hooray, IAB is fully set up. Now, let's get an inventory of stuff we own.
                    Log_d("Setup successful. Querying inventory.");
                    setupDone = true;
                } else {
                    // Oh noes, there was a problem.
                    setupDone = false;
                    Log_e("**** Error: Problem setting up in-app billing: " + result);
                    Toast.makeText(mainContext, "Problem setting up in-app billing: " + result,
                            Toast.LENGTH_SHORT).show();
                }
                notifyServiceAvailable(result.isSuccess());
            }
        });
    } catch (Throwable e) {
        e.printStackTrace();
    }
}

From source file:br.gov.jfrj.siga.model.dao.HibernateUtil.java

public static void configurarHibernate(String resource, String hibernateConnectionUrl,
        Class<?>... classesAnotadas) {

    try {/*from   www. j  av  a2s  .com*/

        Boolean fUseDatasource = null;
        String sUseDatasource = System.getProperty("siga.use.datasource");

        if (sUseDatasource != null) {
            fUseDatasource = Boolean.valueOf(sUseDatasource);
        }

        if (classesAnotadas != null)
            conf = criarConfiguracao(resource, classesAnotadas);
        else
            conf = criarConfiguracao(resource);

        if (hibernateConnectionUrl != null)
            conf.setProperty("hibernate.connection.url", hibernateConnectionUrl);

        if (fUseDatasource != null) {

            if (fUseDatasource) {

                conf.setProperty("connection.datasource", conf.getProperty("siga.connection.datasource"));

                conf.getProperties().remove("hibernate.connection.url");
                conf.getProperties().remove("hibernate.connection.username");
                conf.getProperties().remove("hibernate.connection.password");
                conf.getProperties().remove("hibernate.connection.driver_class");

            } else {

                conf.getProperties().remove("connection.datasource");

                conf.setProperty("hibernate.connection.url", conf.getProperty("siga.hibernate.connection.url"));
                conf.setProperty("hibernate.connection.username",
                        conf.getProperty("siga.hibernate.connection.username"));
                conf.setProperty("hibernate.connection.password",
                        conf.getProperty("siga.hibernate.connection.password"));
                conf.setProperty("hibernate.connection.driver_class",
                        conf.getProperty("siga.hibernate.connection.driver_class"));
            }
        }

        if (hibernateConnectionUrl != null && hibernateConnectionUrl.equals("test")) {

            conf.getProperties().remove("connection.datasource");

            conf.setProperty("hibernate.connection.url",
                    conf.getProperty("siga.test.hibernate.connection.url"));
            conf.setProperty("hibernate.connection.username",
                    conf.getProperty("siga.test.hibernate.connection.username"));
            conf.setProperty("hibernate.connection.password",
                    conf.getProperty("siga.test.hibernate.connection.password"));
            conf.setProperty("hibernate.connection.driver_class",
                    conf.getProperty("siga.test.hibernate.connection.driver_class"));
        }

        sessionFactory = conf.buildSessionFactory();

    } catch (final Throwable ex) {

        // Make sure you log the exception, as it might be swallowed
        System.out.println("HibernateUtil");
        ex.printStackTrace();
        HibernateUtil.logger.error("No foi possvel configurar o hibernate.", ex);

        throw new ExceptionInInitializerError(ex);
    }
}

From source file:io.bitsquare.common.util.Utilities.java

public static void copyToClipboard(String content) {
    try {//from  w  w  w .  j  a v a2  s.  c  om
        if (content != null && content.length() > 0) {
            Clipboard clipboard = Clipboard.getSystemClipboard();
            ClipboardContent clipboardContent = new ClipboardContent();
            clipboardContent.putString(content);
            clipboard.setContent(clipboardContent);
        }
    } catch (Throwable e) {
        log.error("copyToClipboard failed " + e.getMessage());
        e.printStackTrace();
    }
}

From source file:Main.java

public static void logToFile(Throwable e) {
    try {/* w ww  .  j  a  va  2s  .  com*/
        StringBuffer sb = new StringBuffer(e.toString() + "\n");
        StackTraceElement[] stElements = e.getStackTrace();
        String newLine = "";

        for (StackTraceElement stElement : stElements) {
            sb.append(newLine);
            sb.append("\tat ");
            sb.append(stElement.toString());
            newLine = "\n";
        }
    } catch (Exception ee) {
        e.printStackTrace();
    }
}

From source file:com.frostwire.android.gui.util.UIUtils.java

private static boolean openAudioInternal(final Context context, String filePath) {
    try {/*from   w  w w. j av a2s.  com*/
        List<FileDescriptor> fds = Librarian.instance().getFiles(context, filePath, true);
        if (fds.size() == 1 && fds.get(0).fileType == Constants.FILE_TYPE_AUDIO) {
            playEphemeralPlaylist(context, fds.get(0));
            UXStats.instance().log(UXAction.LIBRARY_PLAY_AUDIO_FROM_FILE);
            return true;
        } else {
            return false;
        }
    } catch (Throwable e) {
        e.printStackTrace();
        return false;
    }
}

From source file:com.ms.commons.test.classloader.util.SimpleAntxLoader.java

public static Properties getAntxProperties(File antxFile) {
    try {/*from ww  w  .  j a v a  2s .c  om*/
        SimpleAntxLoader sal = new SimpleAntxLoader(antxFile);

        return sal.getProperties();
    } catch (Throwable t) {
        t.printStackTrace();
        return null;
    }
}

From source file:com.adito.agent.client.ProxyUtil.java

/**
 * Attempt to proxy settings from Internet Explorer.
 * //from w  w w  .  j  ava 2s . co m
 * @return internet explorer proxy settings
 * @throws IOException if IE settings could not be obtained for some reason
 */
public static BrowserProxySettings lookupIEProxySettings() throws IOException {

    try {
        Vector addresses = new Vector();
        Vector proxies = new Vector();
        String proxyServerValue = null;
        String proxyOveride = null;

        /* Only use jRegistry if on Windows, running 1.3 or up Java
         * and NOT Windows Vista with JDK6.0 (because of jvm crash)
         */

        if (Utils.isSupportedJRE("+1.3") && Utils.isSupportedPlatform(
                "Windows") /*&&
                           !(Utils.isSupportedOSVersion("+6.0") && Utils.isSupportedJRE("+1.6"))*/) {

            /*
             * We can use jRegistryKey API to lookup IE settings in the
             * registry
             */
            //                RegistryKey key = new RegistryKey(RootKey.HKEY_CURRENT_USER,
            //                                "Software\\Microsoft\\Windows\\CurrentVersion\\Internet Settings"); //$NON-NLS-1$

            String proxyEnable = WinRegistry.getRegistryValue("user",
                    "Software\\Microsoft\\Windows\\CurrentVersion\\Internet Settings", "ProxyEnable", "0");
            if (proxyEnable != null) { //$NON-NLS-1$
                /*
                 * We have ProxyEnable so check to see if we are using a
                 * proxy
                 */
                if (proxyEnable.equals("1")) { //$NON-NLS-1$ //$NON-NLS-2$

                    proxyServerValue = WinRegistry.getRegistryValue("user",
                            "Software\\Microsoft\\Windows\\CurrentVersion\\Internet Settings", "ProxyServer",
                            null);
                    if (proxyServerValue != null) { //$NON-NLS-1$
                        /**
                         * We have some proxy settings. The values will be
                         * in the format "server.proxy.net:8888" or
                         */

                        proxyOveride = WinRegistry.getRegistryValue("user",
                                "Software\\Microsoft\\Windows\\CurrentVersion\\Internet Settings",
                                "ProxyOverride", null);
                    }
                } else {

                }
            }
        } else {
            if (System.getProperty("java.vendor").startsWith("Microsoft")) { //$NON-NLS-1$ //$NON-NLS-2$
                try {
                    Class clazz = Class.forName("com.ms.lang.RegKey"); //$NON-NLS-1$
                    int userRoot = clazz.getField("USER_ROOT").getInt(null); //$NON-NLS-1$
                    int keyOpenAll = clazz.getField("KEYOPEN_ALL").getInt(null); //$NON-NLS-1$
                    // #ifdef DEBUG
                    log.info(Messages.getString("ProxyUtil.lookingForRoot")); //$NON-NLS-1$
                    // #endif
                    Object rootKey = clazz.getMethod("getRootKey", new Class[] { int.class }).invoke(null, //$NON-NLS-1$
                            new Object[] { new Integer(userRoot) });
                    // #ifdef DEBUG
                    log.info(Messages.getString("ProxyUtil.getIERegistryKey")); //$NON-NLS-1$
                    // #endif
                    Object key = clazz.getConstructor(new Class[] { clazz, String.class, int.class })
                            .newInstance(new Object[] { rootKey,
                                    "Software\\Microsoft\\Windows\\CurrentVersion\\Internet Settings", //$NON-NLS-1$
                                    new Integer(keyOpenAll) });
                    // #ifdef DEBUG
                    log.info(Messages.getString("ProxyUtil.checkingIfProxyEnabled")); //$NON-NLS-1$
                    // #endif
                    if (((Integer) (clazz.getMethod("getIntValue", new Class[] { String.class }).invoke(key, //$NON-NLS-1$
                            new Object[] { "ProxyEnable" }))).intValue() == 1) { //$NON-NLS-1$
                        // #ifdef DEBUG
                        log.info(Messages.getString("ProxyUtil.gettingProxyServerList")); //$NON-NLS-1$
                        // #endif
                        proxyServerValue = (String) (clazz.getMethod("getStringValue", //$NON-NLS-1$
                                new Class[] { String.class, String.class })
                                .invoke(key, new Object[] { "ProxyServer", "" })); //$NON-NLS-1$ //$NON-NLS-2$
                        // #ifdef DEBUG
                        log.info(Messages.getString("ProxyUtil.gettingProxyOverides")); //$NON-NLS-1$
                        // #endif
                        proxyOveride = (String) (clazz
                                .getMethod("getStringValue", new Class[] { String.class, String.class }) //$NON-NLS-1$
                                .invoke(key, new Object[] { "ProxyOverride", "" })); //$NON-NLS-1$ //$NON-NLS-2$
                    }
                } catch (Throwable t) {
                    t.printStackTrace();
                }

            } else {
                // #ifdef DEBUG
                log.info(MessageFormat.format(Messages.getString("ProxyUtil.unsupportedJavaRuntime"), //$NON-NLS-1$
                        new Object[] { System.getProperty("java.version"), //$NON-NLS-1$
                                System.getProperty("java.vendor") })); //$NON-NLS-1$
                // #endif
            }

        }

        ProxyInfo p;

        if (proxyServerValue != null && proxyServerValue.indexOf(';') > -1) {
            /**
             * Format is multiple
             * "ftp=ftp.com:4444;gopher=gopher.com:3333;http=198.162.1.119:8888;https=https.com:2222;socks=socks.com:1111"
             */
            StringTokenizer tokens = new StringTokenizer(proxyServerValue, ";"); //$NON-NLS-1$

            while (tokens.hasMoreTokens()) {
                p = createProxyInfo(tokens.nextToken(), "IE Proxy Settings"); //$NON-NLS-1$
                proxies.addElement(p);
            }

        } else if (proxyServerValue != null) {
            /**
             * Format is single "http=server.proxy.net:8888" or
             * "server.proxy.net:8888"
             */
            p = createProxyInfo(proxyServerValue, "IE Proxy Settings"); //$NON-NLS-1$
            proxies.addElement(p);
        }

        BrowserProxySettings bps = new BrowserProxySettings();
        bps.setBrowser("Internet Explorer"); //$NON-NLS-1$
        bps.setProxies(new ProxyInfo[proxies.size()]);
        proxies.copyInto(bps.getProxies());
        if (proxyOveride != null) {

            StringTokenizer tokens = new StringTokenizer(proxyOveride, ";"); //$NON-NLS-1$

            while (tokens.hasMoreTokens()) {
                addresses.addElement(tokens.nextToken());
            }
        }

        bps.setBypassAddr(new String[addresses.size()]);
        addresses.copyInto(bps.getBypassAddr());
        return bps;

    } catch (Throwable t) {
        t.printStackTrace();
        throw new IOException(MessageFormat.format(Messages.getString("ProxyUtil.failedToLookupIEProxies"), //$NON-NLS-1$
                new Object[] { t.getMessage() }));
    }
}

From source file:com.aw.support.reflection.MethodInvoker.java

public static Object invoke(Object target, Object[] methodName, Object param) throws Throwable {
    List results = new ArrayList();
    try {//from  w  w w  . j a  v  a  2 s  .  c  o m
        Class cls = target.getClass();
        Class[] paramTypes = new Class[] { Object.class };
        for (int i = 0; i < methodName.length; i++) {
            Method method = cls.getMethod((String) methodName[i], paramTypes);
            Object obj = method.invoke(target, param);
            if (obj != null) {
                results.add(obj);
            }
        }
    } catch (Throwable e) {
        if (e.getCause() instanceof AWException) {
            e.getCause().printStackTrace();
            throw (AWException) e.getCause();
        }
        e.printStackTrace();
        throw e;
    }
    return results;
}

From source file:com.pentaho.di.purge.RepositoryCleanupUtil.java

/**
 * Print stack trace on error/*from   w  w w  .  j a  v  a 2 s . c o m*/
 * 
 * @param t
 */
private static void writeOut(Throwable t) {
    t.printStackTrace();
    exit(1);
}

From source file:com.aw.support.reflection.MethodInvoker.java

public static Object invoke(Object target, String methodName, Object[] parameters, Class[] parameterTypes) {
    Object result = null;/* ww  w .j  a v  a2  s.  com*/
    try {
        Class cls = target.getClass();
        Class[] paramTypes = parameterTypes;
        for (int i = 0; i < paramTypes.length; i++) {
            if (parameterTypes[i] == null) {
                paramTypes[i] = parameters[i].getClass();
            }
        }
        Method method = cls.getMethod(methodName, paramTypes);
        method.setAccessible(true);
        result = method.invoke(target, parameters);
    } catch (Throwable e) {
        if (!(e instanceof AWException)) {
            if (e.getCause() instanceof AWException) {
                throw ((AWException) e.getCause());
            }
            e.printStackTrace();
            throw new AWSystemException("Problems calling the method:" + methodName, e);
        } else {
            throw (AWException) e;
        }
    }
    return result;
}