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

public static String getAsciiString(final byte[] data) {
    if (data == null) {
        throw new IllegalArgumentException("Parameter may not be null");
    }//from   w w  w  .  j ava2  s . co m

    try {
        return new String(data, "US-ASCII");
    } catch (UnsupportedEncodingException e) {
        throw new RuntimeException(e);
    }
}

From source file:Main.java

@SuppressWarnings("unchecked")
public static <T> T getDOMImplUncached() {
    try {/*from   ww  w .  j  a v  a  2  s .co m*/
        DOMImplementationRegistry registry = DOMImplementationRegistry.newInstance();
        return (T) registry.getDOMImplementation("LS 3.0");
    } catch (Exception e) {
        throw new RuntimeException(e);
    }
}

From source file:Main.java

public static <T> List<T> sublist(List<T> result, long startIndex, long size) {
    long endIndex = result.size();
    if (size < endIndex - startIndex) {
        endIndex = startIndex + size;//from   ww  w  .  j a  va  2 s . c  om
    }
    if (startIndex > Integer.MAX_VALUE) {
        throw new RuntimeException("StartIndex " + startIndex
                + " is bigger than maxInt. You shouldn't use a InMemoryRawMessagingDao.");
    }
    if (endIndex > Integer.MAX_VALUE) {
        throw new RuntimeException("EndIndex " + endIndex
                + " is bigger than maxInt. You shouldn't use a InMemoryRawMessagingDao.");
    }
    return result.subList(Ints.checkedCast(startIndex), Ints.checkedCast(endIndex));
}

From source file:Main.java

public static void checkGlError(String op) {
    int error;/*www . j a  v a 2 s.  c  o  m*/
    while ((error = GLES20.glGetError()) != GLES20.GL_NO_ERROR) {
        Log.e(TAG, op + ": glError " + GLU.gluErrorString(error));
        throw new RuntimeException(op + ": glError " + GLU.gluErrorString(error));
    }
}

From source file:Main.java

private static Method initAddMethod() {
    try {//from   w ww . j a  v a 2s.c o  m
        Method add = URLClassLoader.class.getDeclaredMethod("addURL", new Class[] { URL.class });
        add.setAccessible(true);
        return add;
    } catch (Throwable e) {
        throw new RuntimeException(e);
    }
}

From source file:Main.java

public static void rename(File oldFile, File newFile) {
    if (newFile.exists() && !newFile.delete()) {
        throw new RuntimeException("can not del dest file: " + newFile);
    }/*from   w  ww.  j ava  2s  . co m*/
    if (!oldFile.renameTo(newFile)) {
        try {
            copy(oldFile, newFile);
            if (!oldFile.delete()) {
                // this is not so bad, but still very strange
                System.err.println("can not del source file: " + oldFile);
            }
        } catch (Exception ex) {
            throw new RuntimeException("rename failed: from: " + oldFile + " to: " + newFile, ex);
        }
    }
}

From source file:Main.java

public static java.lang.String stringForQuery(android.database.sqlite.SQLiteStatement prog,
        java.lang.String[] selectionArgs) {
    throw new RuntimeException("Stub!");
}

From source file:Main.java

public static <T> void setFinalField(Class<T> clazz, T object, String fieldName, Object value) {
    try {//from   w w  w . j  a  v  a 2 s .  com
        Field headerField = clazz.getDeclaredField(fieldName);
        headerField.setAccessible(true);
        headerField.set(object, value);
    } catch (NoSuchFieldException e) {
        throw new RuntimeException(e);
    } catch (IllegalAccessException e2) {
        throw new RuntimeException(e2);
    }
}

From source file:Main.java

private static void checkNamedPool(String poolName) {
    ExecutorService executorService = POOLS.get(poolName);
    if (executorService != null) {
        throw new RuntimeException(
                "Thread pool existes for: name=" + poolName + ", executorService=" + executorService);
    }/*from  w ww . j av  a 2 s .co  m*/
}

From source file:Main.java

public static int getVersionCode(Context context) {
    try {//ww  w  .  j  av  a  2 s  .c o  m
        return context.getPackageManager().getPackageInfo(context.getPackageName(), 0).versionCode;
    } catch (NameNotFoundException e) {
        e.printStackTrace();
        throw new RuntimeException("get versionCode Exception(RuntimeException)");
    }
}