Example usage for java.lang Exception toString

List of usage examples for java.lang Exception toString

Introduction

In this page you can find the example usage for java.lang Exception toString.

Prototype

public String toString() 

Source Link

Document

Returns a short description of this throwable.

Usage

From source file:aes_encryption.AES_Encryption.java

public static String decrypt(String strToDecrypt) {

    try {//  w w  w  .j av a2 s. com
        Cipher cipher = Cipher.getInstance("AES/ECB/PKCS5PADDING");

        cipher.init(Cipher.DECRYPT_MODE, secretKey);
        setDecryptedString(new String(cipher.doFinal(Base64.decodeBase64(strToDecrypt))));

    } catch (Exception e) {

        System.out.println("Error while decrypting: " + e.toString());
    }
    return null;
}

From source file:watchtower.common.automation.CommandUtils.java

public static Command fromJson(byte[] commandJson) {
    try {/*from  w  w  w.j  a  v  a  2s.c  o  m*/
        String jsonString = StringEscapeUtils.unescapeJava(new String(commandJson, "UTF-8"));
        return OBJECT_MAPPER.readValue(jsonString, Command.class);
    } catch (Exception e) {
        logger.error("Failed to parse command json: {}", e.toString());
    }

    return null;
}

From source file:com.microsoft.azure.servicebus.samples.autoforward.AutoForward.java

public static int runApp(String[] args, Function<String, Integer> run) {
    try {//w w  w. ja  va  2  s .  co  m

        String connectionString = null;

        // parse connection string from command line
        Options options = new Options();
        options.addOption(new Option("c", true, "Connection string"));
        CommandLineParser clp = new DefaultParser();
        CommandLine cl = clp.parse(options, args);
        if (cl.getOptionValue("c") != null) {
            connectionString = cl.getOptionValue("c");
        }

        // get overrides from the environment
        String env = System.getenv(SB_SAMPLES_CONNECTIONSTRING);
        if (env != null) {
            connectionString = env;
        }

        if (connectionString == null) {
            HelpFormatter formatter = new HelpFormatter();
            formatter.printHelp("run jar with", "", options, "", true);
            return 2;
        }
        return run.apply(connectionString);
    } catch (Exception e) {
        System.out.printf("%s", e.toString());
        return 3;
    }
}

From source file:com.plnyyanks.frcnotebook.datafeed.GET_Request.java

public static String getWebData(String url, boolean tbaheader) {

    InputStream is = null;/*from  w w w .ja va 2  s.  co  m*/
    String result = "";

    // HTTP
    try {
        HttpClient httpclient = new DefaultHttpClient(); // for port 80 requests!
        HttpGet httpget = new HttpGet(url);
        if (tbaheader)
            httpget.addHeader(Constants.TBA_HEADER, Constants.TBA_HEADER_TEXT);
        HttpResponse response = httpclient.execute(httpget);
        HttpEntity entity = response.getEntity();
        is = entity.getContent();
    } catch (Exception e) {
        Log.e(Constants.LOG_TAG, e.toString());
        return null;
    }

    // Read response to string
    try {
        BufferedReader reader = new BufferedReader(new InputStreamReader(is, "utf-8"), 8);
        StringBuilder sb = new StringBuilder();
        String line = null;
        while ((line = reader.readLine()) != null) {
            sb.append(line + "\n");
        }
        is.close();
        result = sb.toString();
    } catch (Exception e) {
        Log.e(Constants.LOG_TAG, e.toString());
        return null;
    }

    return result;

}

From source file:Main.java

public static String formatException(Exception exception) {
    String formattedString = "Internal Error";
    Log.e("App Error", exception.toString());
    Log.getStackTraceString(exception);//from w w  w .j  a  va 2  s .c o m

    String temp = exception.getMessage();

    if (temp != null && temp.length() > 0) {
        formattedString = temp.split("\\(")[0];
        if (temp != null && temp.length() > 0) {
            return formattedString;
        }
    }

    return formattedString;
}

From source file:Main.java

private static Map<UUID, String> readPageNameHashesFromFile(File folder) {
    Map<UUID, String> map = new HashMap<UUID, String>();

    try {//from  ww  w  .ja  v a2s . c o m
        FileInputStream fis = new FileInputStream(folder.getAbsolutePath() + fileName);
        ObjectInputStream ois = new ObjectInputStream(fis);
        map = (Map<UUID, String>) ois.readObject();
        ois.close();
        printMap();
    } catch (Exception e) {
        e.printStackTrace();
        Log.e("Read from file", e.toString());
    }

    return map;
}

From source file:com.keybox.common.util.AppConfig.java

/**
 * removes property from the config//w  w  w .j  a  v a2 s .  c  om
 *
 * @param name property name
 */
public static void removeProperty(String name) {

    //remove property
    try {
        prop.clearProperty(name);
        prop.save();
    } catch (Exception ex) {
        log.error(ex.toString(), ex);
    }
}

From source file:com.keybox.common.util.AppConfig.java

/**
 * updates the property in the config//w  ww . j a  va2s  .c o  m
 *
 * @param name property name
 * @param value property value
 */
public static void updateProperty(String name, String value) {

    //remove property
    try {
        prop.setProperty(name, value);
        prop.save();
    } catch (Exception ex) {
        log.error(ex.toString(), ex);
    }
}

From source file:watchtower.common.incident.IncidentUtils.java

public static Incident fromJson(byte[] incidentJson) {
    try {//from w  ww. ja  v a 2  s .co m
        String jsonString = StringEscapeUtils.unescapeJava(new String(incidentJson, "UTF-8"));
        return OBJECT_MAPPER.readValue(jsonString, Incident.class);
    } catch (Exception e) {
        logger.error("Failed to parse incident json: {}", e.toString());
    }

    return null;
}

From source file:watchtower.common.incident.IncidentUtils.java

public static Incident fromJson(String incidentJson) {
    try {// w w  w .  j av a 2  s  .  c  o m
        String jsonString = StringEscapeUtils.unescapeJava(incidentJson);
        return OBJECT_MAPPER.readValue(jsonString, Incident.class);
    } catch (Exception e) {
        logger.error("Failed to parse incident json: {}", e.toString());
    }

    return null;
}