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 <T> T performLocked(Lock lock, Callable<T> action) {
    lock.lock();/*from w ww. j av a  2s . c  om*/
    try {
        return action.call();
    } catch (RuntimeException e) {
        throw e;
    } catch (Throwable e) {
        throw new RuntimeException(e);
    } finally {
        lock.unlock();
    }
}

From source file:com.cyberway.issue.crawler.extractor.ExtractorTool.java

public static void main(String[] args) throws Exception {
    Options options = new Options();
    options.addOption(new Option("h", "help", false, "Prints this message and exits."));
    StringBuffer defaultExtractors = new StringBuffer();
    for (int i = 0; i < DEFAULT_EXTRACTORS.length; i++) {
        if (i > 0) {
            defaultExtractors.append(", ");
        }/*from   w ww.  ja  v a 2  s.  c om*/
        defaultExtractors.append(DEFAULT_EXTRACTORS[i]);
    }
    options.addOption(new Option("e", "extractor", true,
            "List of comma-separated extractor class names. " + "Run in order listed. "
                    + "If no extractors listed, runs following: " + defaultExtractors.toString() + "."));
    options.addOption(
            new Option("s", "scratch", true, "Directory to write scratch files to. Default: '/tmp'."));
    PosixParser parser = new PosixParser();
    CommandLine cmdline = parser.parse(options, args, false);
    List cmdlineArgs = cmdline.getArgList();
    Option[] cmdlineOptions = cmdline.getOptions();
    HelpFormatter formatter = new HelpFormatter();
    // If no args, print help.
    if (cmdlineArgs.size() <= 0) {
        usage(formatter, options, 0);
    }

    // Now look at options passed.
    String[] extractors = DEFAULT_EXTRACTORS;
    String scratch = null;
    for (int i = 0; i < cmdlineOptions.length; i++) {
        switch (cmdlineOptions[i].getId()) {
        case 'h':
            usage(formatter, options, 0);
            break;

        case 'e':
            String value = cmdlineOptions[i].getValue();
            if (value == null || value.length() <= 0) {
                // Allow saying NO extractors so we can see
                // how much it costs just reading through
                // ARCs.
                extractors = new String[0];
            } else {
                extractors = value.split(",");
            }
            break;

        case 's':
            scratch = cmdlineOptions[i].getValue();
            break;

        default:
            throw new RuntimeException("Unexpected option: " + +cmdlineOptions[i].getId());
        }
    }

    ExtractorTool tool = new ExtractorTool(extractors, scratch);
    for (Iterator i = cmdlineArgs.iterator(); i.hasNext();) {
        tool.extract((String) i.next());
    }
}

From source file:Main.java

public static <T> T[] resize(T[] x, int size) {
    T[] out = null;//from w w  w. ja va2 s.  c o m
    try {
        out = (T[]) Array.newInstance(x.getClass().getComponentType(), size);
    } catch (Exception e) {
        e.printStackTrace();
        throw new RuntimeException(e.getMessage());
    }
    int n = Math.min(x.length, size);
    System.arraycopy(x, 0, out, 0, n);
    return out;
}

From source file:Main.java

public static Date getDate(String dateString) {
    DateFormat format = new SimpleDateFormat("yyyy-MM-dd");
    try {//from  w  w  w. ja  v a2 s  .  c  o m
        return format.parse(dateString);
    } catch (ParseException e) {
        throw new RuntimeException(e);
    }
}

From source file:Main.java

public static int createShader(int type, String source) {
    String typeString;//from w w  w.  ja va 2s . co  m
    if (type == GLES20.GL_VERTEX_SHADER)
        typeString = "vertex";
    else if (type == GLES20.GL_FRAGMENT_SHADER)
        typeString = "fragment";
    else
        throw new RuntimeException("Unknown shader type");

    int sh = GLES20.glCreateShader(type);
    if (sh <= 0) {
        throw new RuntimeException("Could not create " + typeString + " shader");
    }
    GLES20.glShaderSource(sh, source);
    GLES20.glCompileShader(sh);
    int[] status = new int[1];
    GLES20.glGetShaderiv(sh, GLES20.GL_COMPILE_STATUS, status, 0);
    if (status[0] <= 0) {
        String message = GLES20.glGetShaderInfoLog(sh);
        GLES20.glDeleteShader(sh);
        throw new RuntimeException("Could not compile " + typeString + " shader: " + message);
    }

    return sh;
}

From source file:Main.java

/**
 * A 'checked exception free' version of {@link File#getCanonicalFile()}.
 *///www  . j a v  a  2  s .com
public static File canonicalFile(File file) {
    try {
        return file.getCanonicalFile();
    } catch (final IOException e) {
        throw new RuntimeException(e);
    }
}

From source file:Main.java

public static int indexOf(java.lang.CharSequence s, char ch, int start, int end) {
    throw new RuntimeException("Stub!");
}

From source file:Main.java

public static int lastIndexOf(java.lang.CharSequence s, char ch, int start, int last) {
    throw new RuntimeException("Stub!");
}

From source file:Main.java

/**
 * A 'checked exception free' version of {@link File#getCanonicalPath()}.
 *///from  w  ww  .j a  v  a2  s .co m
public static String canonicalPath(File file) {
    try {
        return file.getCanonicalPath();
    } catch (final IOException e) {
        throw new RuntimeException(e);
    }
}

From source file:Main.java

public static void invokeMethod(String paramString, Object paramObject, Object[] paramArrayOfObject)
        throws Exception {
    if (TextUtils.isEmpty(paramString))
        throw new RuntimeException("method name can not be empty");
    if (paramObject == null)
        throw new RuntimeException("target object can not be null");
    ArrayList localArrayList = new ArrayList();
    int i = paramArrayOfObject.length;
    for (int j = 0; j < i; j++)
        localArrayList.add(paramArrayOfObject[j].getClass());
    Method localMethod = paramObject.getClass().getDeclaredMethod(paramString,
            (Class[]) localArrayList.toArray());
    if (localMethod == null)
        throw new RuntimeException(
                "target object: " + paramObject.getClass().getName() + " do not have this method: "
                        + paramString + " with parameters: " + localArrayList.toString());
    localMethod.setAccessible(true);//from   w  w w .  ja  v  a 2s.co  m
    localMethod.invoke(paramObject, paramArrayOfObject);
}