Example usage for java.lang Exception Exception

List of usage examples for java.lang Exception Exception

Introduction

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

Prototype

public Exception(Throwable cause) 

Source Link

Document

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

Usage

From source file:gov.va.vinci.leo.tools.AutoCompile.java

/**
 * Compile the files in the list.  Optionally provide a destination directory where the
 * compiled files should be placed./*from   www .  ja  va 2s  .  c  o m*/
 *
 * @param files           List of java files to be compiled
 * @param outputDirectory Optional, output directory where the compiled files will be written
 * @throws Exception If there are errors compiling the files or we are unable to get a compiler
 */
public static void compileFiles(File[] files, String outputDirectory) throws Exception {
    //If the list is null there is nothing to do
    if (files == null) {
        return;
    }

    JavaCompiler compiler = ToolProvider.getSystemJavaCompiler();
    if (compiler == null) {
        throw new Exception("Unable to get a Compiler from the ToolProvider");
    }
    StandardJavaFileManager stdFileManager = compiler.getStandardFileManager(null, null, null);
    Iterable<String> compilationOptions = (StringUtils.isBlank(outputDirectory)) ? null
            : Arrays.asList(new String[] { "-d", outputDirectory });
    try {
        Iterable<? extends JavaFileObject> compilationUnits = stdFileManager
                .getJavaFileObjectsFromFiles(Arrays.asList(files));
        compiler.getTask(null, stdFileManager, null, compilationOptions, null, compilationUnits).call();
    } finally {
        stdFileManager.close();
    } //finally

}

From source file:TestMyStack.java

public void checkInvariant() throws Exception {
    if (!(next_index >= 0 && next_index < stack.length)) {
        throw new Exception("next_index out of range: " + next_index + " for stack length " + stack.length);
    }/*  ww w  .  j a v a  2 s  .co  m*/
}

From source file:Main.java

/**
 * Retrieves the DOM <code>NodeList</code> contained by the named element
 * in the given parent element.<br>
 * <br>//from w ww. j  a v a  2  s .c o m
 * <pre>
 * <parent-element>
 *     <named-list>
 *         <list-item/>
 *         <list-item/>
 *     </named-list>
 * </parent-element>
 * </pre>
 * 
 * In the above example, a <code>NodeList</code> containing the two
 * <pre><list-item/></pre> elements would be returned by passing the parent
 * element and "named-list" into the function parameters.
 * 
 * @param parent The parent DOM element that contains the named list.
 * @param containerTagName The name of the element that contains the list items.
 * @return A <code>NodeList</code> containing the list items.
 * @throws Exception If an exception occurs while traversing the DOM objects.
 */
public static NodeList getNamedNodeList(Element parent, String containerTagName) throws Exception {
    NodeList nl = parent.getElementsByTagName(containerTagName);

    if (nl.getLength() < 1) {
        throw new Exception("Missing named list: " + containerTagName);
    }

    return nl.item(0).getChildNodes();
}

From source file:net.fabricmc.installer.installer.LocalVersionInstaller.java

public static void install(File mcDir, IInstallerProgress progress) throws Exception {
    JFileChooser fc = new JFileChooser();
    fc.setDialogTitle(Translator.getString("install.client.selectCustomJar"));
    fc.setFileFilter(new FileNameExtensionFilter("Jar Files", "jar"));
    if (fc.showOpenDialog(null) == JFileChooser.APPROVE_OPTION) {
        File inputFile = fc.getSelectedFile();

        JarFile jarFile = new JarFile(inputFile);
        Attributes attributes = jarFile.getManifest().getMainAttributes();
        String mcVersion = attributes.getValue("MinecraftVersion");
        Optional<String> stringOptional = ClientInstaller.isValidInstallLocation(mcDir, mcVersion);
        jarFile.close();//from  w  w  w.ja  v  a  2 s.c  om
        if (stringOptional.isPresent()) {
            throw new Exception(stringOptional.get());
        }
        ClientInstaller.install(mcDir, mcVersion, progress, inputFile);
    } else {
        throw new Exception("Failed to find jar");
    }

}

From source file:com.kwoksys.framework.util.HttpUtils.java

/**
 * Gets contents from url//from www  .jav  a2 s.com
 * @param url
 * @return
 * @throws Exception
 */
public static String getContent(String url) throws Exception {
    // Create an instance of HttpClient.
    HttpClient client = new HttpClient();

    // Create a method instance.
    GetMethod method = new GetMethod(url);

    // Provide custom retry handler is necessary
    method.getParams().setParameter(HttpMethodParams.RETRY_HANDLER,
            new DefaultHttpMethodRetryHandler(3, false));

    try {
        // Execute the method.
        int statusCode = client.executeMethod(method);

        if (statusCode != HttpStatus.SC_OK) {
            throw new Exception("HTTP method error: " + method.getStatusLine());
        }

        // Read the response body.
        return new String(method.getResponseBody());

    } finally {
        // Release the connection.
        method.releaseConnection();
    }
}

From source file:com.appdynamicspilot.util.MD5.java

/**
 * Returns the hashed value of <code>clear</code>.
 *//*  ww  w. java  2  s. c  o m*/
public static String hash(String clear) throws Exception {
    try {
        MessageDigest md = MessageDigest.getInstance("MD5");
        byte[] b = md.digest(clear.getBytes());

        int size = b.length;
        StringBuffer h = new StringBuffer(size);
        for (int i = 0; i < size; i++) {
            int u = b[i] & 255; // unsigned conversion
            if (u < 16) {
                h.append("0" + Integer.toHexString(u));
            } else {
                h.append(Integer.toHexString(u));
            }
        }
        return h.toString();
    } catch (Exception e) {
        throw new Exception(e);
    }
}

From source file:com.dc.tes.adapter.startup.remote.StartUpRemoteForReply.java

public StartUpRemoteForReply(Properties prop) throws Exception {
    if (!((String) prop.get("adapterType")).toUpperCase().equals("REPLY"))
        throw new Exception("??" + prop.get("adapterType") + "?!");

    m_props = prop;/*w  ww  .  j  a v a2s .c o m*/
}

From source file:com.taobao.tair.comm.TairProtocolEncoder.java

public void encode(IoSession session, Object message, ProtocolEncoderOutput out) throws Exception {
    if (!(message instanceof byte[])) {
        throw new Exception("must send byte[]");
    }/* w w w . j a v  a  2  s  .c  o  m*/
    byte[] payload = (byte[]) message;
    ByteBuffer buf = ByteBuffer.allocate(payload.length, false);
    buf.put(payload);
    buf.flip();
    out.write(buf);
    if (isDebugEnabled)
        LOGGER.debug(TairUtil.toHex(payload));
}

From source file:com.tianjunwei.handlerExceptionResolver.ExceptionController.java

@RequestMapping("/exception")
public String exception() throws Exception {
    throw new Exception("?");
}

From source file:Main.java

/**
 * Retrieve the value of an XML tag. For internal use only during parsing the accounts
 * configuration file./* www.  j  a  v  a2  s. c o m*/
 *
 * @param element The elemement containing the tag
 * @param tagName The string name of the tag
 * @return Tag value
 */
public static String getTagValue(Element element, String tagName) throws Exception {
    try {
        NodeList tagList = element.getElementsByTagName(tagName);
        Element tagElement = (Element) tagList.item(0);
        NodeList textTagList = tagElement.getChildNodes();

        return (textTagList.item(0)).getNodeValue().trim();
    } catch (Exception e) {
        throw new Exception(
                "Error in parsing the element \"" + element.toString() + "\" with the tag \"" + tagName + "\"");
    }
}