Example usage for java.lang IllegalArgumentException IllegalArgumentException

List of usage examples for java.lang IllegalArgumentException IllegalArgumentException

Introduction

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

Prototype

public IllegalArgumentException(String message, Throwable cause) 

Source Link

Document

Constructs a new exception with the specified detail message and cause.

Usage

From source file:Main.java

private static void throwExceptionForInvalidXmlFile(Throwable rootCause, File deploymentDescriptorFile) {
    throw new IllegalArgumentException(
            "The provided descriptor is not a valid XML file:" + deploymentDescriptorFile.getAbsolutePath(),
            rootCause);/* w  ww .  ja  v  a  2  s  .c o m*/
}

From source file:Main.java

static DataFlavor newDataFlavor(final String mimeType) {
    try {// w w w  .  j a va  2s.c  o m
        return new DataFlavor(mimeType);
    } catch (final ClassNotFoundException e) {
        throw new IllegalArgumentException("Cannot create data flavor for " + mimeType, e);
    }
}

From source file:Main.java

/**
 * Combine a host and port into an authority string.
 *//*from w  w  w  .j  ava  2 s.com*/
public static String authorityFromHostAndPort(String host, int port) {
    try {
        return new URI(null, null, host, port, null, null, null).getAuthority();
    } catch (URISyntaxException ex) {
        throw new IllegalArgumentException("Invalid host or port: " + host + " " + port, ex);
    }
}

From source file:Main.java

public static void setField(Field field, Object target, Object value) {
    if (!Modifier.isPublic(field.getModifiers())) {
        field.setAccessible(true);/* w ww.j ava 2s.c o m*/
    }
    try {
        field.set(target, value);
    } catch (IllegalAccessException iae) {
        throw new IllegalArgumentException("Could not set field " + field, iae);
    }
}

From source file:Main.java

private static InputStream openFile(File configFile) {
    try {//  w ww. j  a  v  a2 s .  co m
        if (configFile == null) {
            return null;
        } else {
            return new FileInputStream(configFile);
        }
    } catch (FileNotFoundException e) {
        throw new IllegalArgumentException("Could not open config file " + configFile, e);
    }
}

From source file:Main.java

public static FileInputStream inputStream(File file) {
    try {/*  w  w w  . java2  s  .  c o  m*/
        return new FileInputStream(file);
    } catch (final FileNotFoundException e) {
        throw new IllegalArgumentException("File " + file + " not found.", e);
    }
}

From source file:Main.java

@SuppressWarnings({ "unchecked", "rawtypes" })
public static <K, V extends Collection<T>, T> void addToMap(Map<K, V> data, K key, T value,
        Class<? extends Collection> clz) {
    V values = data.get(key);//from ww  w  . ja  v a 2s . c o  m
    if (values == null) {
        try {
            values = (V) clz.newInstance();
        } catch (InstantiationException e) {
            throw new IllegalArgumentException("Failed to create collection class", e);
        } catch (IllegalAccessException e) {
            throw new IllegalArgumentException("Failed to create collection class", e);
        }

        data.put(key, values);
    }

    values.add(value);
}

From source file:Main.java

public static void serialize(Object object, File file) {
    try {//www  . j  av a2  s. c  o m
        serialize(object, new FileOutputStream(file));
    } catch (final FileNotFoundException e) {
        throw new IllegalArgumentException("File must exist.", e);
    }
}

From source file:Main.java

/**
 * Initializes the Cipher for use.//from   w w  w .j a  v a 2s  .c o  m
 */
public static <T extends AlgorithmParameterSpec> T getParameterSpec(Cipher cipher,
        Class<T> parameterSpecClass) {
    try {
        return cipher.getParameters().getParameterSpec(parameterSpecClass);
    } catch (InvalidParameterSpecException e) {
        throw new IllegalArgumentException("Unable to access parameter", e);
    }
}