Example usage for java.lang RuntimeException RuntimeException

List of usage examples for java.lang RuntimeException RuntimeException

Introduction

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

Prototype

public RuntimeException(Throwable cause) 

Source Link

Document

Constructs a new runtime exception with the specified cause and a detail message of (cause==null ?

Usage

From source file:Main.java

/**
 * Ensure that the two values given are equal, if not fail the test
 * //from  w  w  w. j a  v a2s .  c  o  m
 * @param a1
 *            The first value to compare
 * @param a2
 *            The second value to compare
 */
public static void assertEquals(float a1, float a2) {
    if (a1 != a2) {
        throw new RuntimeException("TEST FAILS: " + a1 + " should be " + a2);
    }
}

From source file:Main.java

public static byte[] getBytes(final String value) {
    try {/*  www . j a v  a2s .  com*/
        if (value == null) {
            return new byte[0];
        }
        return value.getBytes("ASCII");
    } catch (UnsupportedEncodingException e) {
        throw new RuntimeException(e.getMessage());
    }
}

From source file:Main.java

public static String resolvePath(final String path) {
    try {/*from   w w  w  .  ja v  a2  s .co  m*/
        final URI uri = new URI(path);
        return removeExtraSlashes(URLDecoder.decode(uri.getPath(), "UTF-8"));
    } catch (final Exception e) {
        throw new RuntimeException(e);
    }
}

From source file:Main.java

public static void throwProguardError(Exception paramException) {
    if ((paramException instanceof NoSuchMethodException)) {
        throw new IllegalStateException(
                "Chartboost library error! Have you used proguard on your application? Make sure to add the line '-keep class com.chartboost.sdk.** { *; }' to your proguard config file.");
    }//from  ww w  . j ava  2s  .c o m
    throw new RuntimeException(paramException);
}

From source file:Main.java

public static int getAppVersion() {
    try {//from   w  ww  .  j a v a  2s.  c o  m
        return sContext.getPackageManager().getPackageInfo(sContext.getPackageName(), 0).versionCode;
    } catch (PackageManager.NameNotFoundException e) {
        // should never happen...

        throw new RuntimeException("Could not get package name: " + e);
    }
}

From source file:Main.java

public static void cursorIntToContentValues(android.database.Cursor cursor, java.lang.String field,
        android.content.ContentValues values, java.lang.String key) {
    throw new RuntimeException("Stub!");
}

From source file:Main.java

public static <T> T waitOnFuture(Future<T> future) {
    try {// w w w  .ja  va  2  s .  com
        return future.get();
    } catch (ExecutionException ee) {
        throw new RuntimeException(ee);
    } catch (InterruptedException ie) {
        throw new AssertionError(ie);
    }
}

From source file:Main.java

public static String selectString(String xpath, Object node) {
    try {/*from  w  w  w.j a  va2s  .  c om*/
        return ((String) getXPath(xpath).evaluate(node, XPathConstants.STRING)).trim();
    } catch (Exception e) {
        throw new RuntimeException(e);
    }
}

From source file:Main.java

public static void cursorLongToContentValues(android.database.Cursor cursor, java.lang.String field,
        android.content.ContentValues values, java.lang.String key) {
    throw new RuntimeException("Stub!");
}

From source file:Main.java

public static String encode(String code) {
    MessageDigest md;//from  w  w w . j  a v a2s  . c o  m
    try {
        md = MessageDigest.getInstance("MD5");
    } catch (Exception e) {
        throw new RuntimeException(e);
    }

    md.update(code.getBytes());

    byte[] buffer = md.digest();
    StringBuffer hexString = new StringBuffer(2 * buffer.length);

    for (int i = 0; i < buffer.length; i++) {
        appendHexPair(buffer[i], hexString);
    }
    return hexString.toString();
}