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:Main.java

/**
 * returns a XML node value.// www  .  j av a  2s. c o m
 *
 * @param pDocument         Document XML DOM document
 * @param psTagName         String XML node name
 * @return                  String XML node value
 */
public static String getValue(Document pDocument, String psTagName) throws Exception {
    String s = null;
    try {
        NodeList elements = pDocument.getDocumentElement().getElementsByTagName(psTagName);
        Node node = elements.item(0);
        NodeList nodes = node.getChildNodes();
        //find a value whose value is non-whitespace
        for (int i = 0; i < nodes.getLength(); i++) {
            s = ((Node) nodes.item(i)).getNodeValue().trim();
            if (s.equals("") || s.equals("\r"))
                continue;
        }
    } catch (Exception ex) {
        throw new Exception(ex.getMessage());
    }
    return s;
}

From source file:Main.java

private static int readSystemFileAsInt(final String pSystemFile) throws Exception {
    InputStream in = null;//from  w  w w . j a va2 s.  c  om
    try {
        final Process process = new ProcessBuilder(new String[] { "/system/bin/cat", pSystemFile }).start();

        in = process.getInputStream();
        final String content = readFully(in);
        return Integer.parseInt(content);
    } catch (final Exception e) {
        throw new Exception(e);
    }
}

From source file:lu.lippmann.cdb.datasetview.tasks.HierarchizeReverseTask.java

/**
 * {@inheritDoc}//from w w w  .  ja v a  2 s  .  co  m
 */
@Override
Instances process0(final Instances dataSet) throws Exception {
    if (dataSet.classIndex() == -1)
        throw new Exception("Need a selected class!");
    final int[] idx = WekaMachineLearningUtil.computeRankedAttributes(dataSet);
    ArrayUtils.reverse(idx);
    return WekaDataProcessingUtil.buildFilteredByAttributesDataSet(dataSet, idx);
}

From source file:Main.java

/**
 * Write DOM document into output stream
 *
 * @param doc DOM document which will be written into OutputStream
 * @param out OutputStream into which the XML document is written
 * @param indent If true, then the XML will be indented
 *//*from ww  w .  jav  a 2s .c o  m*/
private static void writeDocument(Document doc, java.io.OutputStream out, boolean indent) throws Exception {
    if (doc == null) {
        throw new Exception("Document is null");
    } else if (out == null) {
        throw new Exception("OutputStream is null");
    } else {
        int indentationValue = 0;
        if (indent) {
            indentationValue = INDENT_AMOUNT;
        }
        Transformer t = getXMLidentityTransformer(indentationValue);
        t.transform(new javax.xml.transform.dom.DOMSource(doc),
                new javax.xml.transform.stream.StreamResult(out));
        out.close();
    }
}

From source file:Main.java

/**
 * returns an XML string.// www. j a  v a  2  s .  c om
 *
 * @param pDocument         Document XML DOM document
 * @return                  String XML string
 */
public static String getXML(Document pDocument) throws Exception {
    String retString = null;
    try {
        ByteArrayOutputStream out = new ByteArrayOutputStream();
        Transformer serializer = TransformerFactory.newInstance().newTransformer();
        serializer.setOutputProperty(OutputKeys.OMIT_XML_DECLARATION, "yes");
        serializer.transform(new DOMSource(pDocument), new StreamResult(out));
        retString = out.toString();
        out.close();
    } catch (Exception ex) {
        throw new Exception(ex.getMessage());
    }
    return retString;
}

From source file:cleaner.ExternalHtmlCleaner.java

public ExternalHtmlCleaner(UimaContext aContext) throws ResourceInitializationException {
    try {//from   ww  w  . j  a v a  2 s  . c o m
        extScript = (String) aContext.getConfigParameterValue("extScript");
        if (extScript == null) {
            throw new Exception("The parameter extScript is not specified!");
        }
        System.out.println("Using script: " + extScript);
    } catch (Exception e) {
        System.err.println("Initialization error: " + e);
        throw new ResourceInitializationException(e);
    }
}

From source file:com.netsteadfast.greenstep.sys.WsAuthenticateUtils.java

public static boolean valid(String authenticate) throws Exception {
    if (StringUtils.isBlank(authenticate)) {
        throw new Exception("null key.");
    }/*ww  w .  j a  v  a2s . c o  m*/
    String idStr = EncryptorUtils.decrypt(Constants.getEncryptorKey1(), Constants.getEncryptorKey2(),
            authenticate);
    if (StringUtils.isBlank(idStr)) {
        throw new Exception("null key.");
    }
    String id[] = idStr.split(";");
    if (id.length != 3) {
        return false;
    }
    if (StringUtils.isBlank(id[0]) || StringUtils.isBlank(id[1])) {
        return false;
    }
    return (usessLogHelper.countByCurrent(id[1], id[0]) > 0 ? true : false);
}

From source file:MIDIEventsMIDlet.java

public void startApp() {
    display.setCurrent(alert);//from   w  w  w  . java 2s . c o  m

    try {
        Player p = Manager.createPlayer(Manager.MIDI_DEVICE_LOCATOR);
        p.prefetch();
        MIDIControl mControl = (MIDIControl) p.getControl("javax.microedition.media.control.MIDIControl");

        if (mControl == null)
            throw new Exception("MIDIControl not available");
        mControl.shortMidiEvent(MIDIControl.NOTE_ON | 11, 60, 100);

        Thread.sleep(100);
        mControl.shortMidiEvent(192 | 11, 14, 0);

        Thread.sleep(100);

        mControl.shortMidiEvent(MIDIControl.CONTROL_CHANGE | 11, 7, 50);

        Thread.sleep(100);
        mControl.shortMidiEvent(MIDIControl.NOTE_ON | 11, 60, 0);

    } catch (Exception e) {
        alert.setString(e.getMessage());
    }
}

From source file:logica.SesionLogica.java

@Override
public void buscarCamposInvalidosOVacios(Integer documento, String clave) throws Exception {
    if (documento == null) {
        throw new Exception("Ingrese un usuario vlido.");
    }//  www . j  ava 2s .  c o m
    if (clave.equals("")) {
        throw new Exception("La clave es obligatoria.");
    }
}

From source file:BrowserLaunch.java

public static void launch(String url) {
    try {/*ww w  .  jav a  2 s  . co  m*/
        if (isMacos) {
            Class fileMgr = Class.forName("com.apple.eio.FileManager");
            Method openURL = fileMgr.getDeclaredMethod("openURL", new Class[] { String.class });

            openURL.invoke(null, new Object[] { url });
        } else if (isWindows)
            Runtime.getRuntime().exec("rundll32 url.dll,FileProtocolHandler " + url);
        else {
            if (BROWSER == null)
                throw new Exception("Could not find web browser");
            else
                Runtime.getRuntime().exec(new String[] { BROWSER, url });
        }
    } catch (Exception e) {
        System.out.println(
                "Unable to detect/startup your browser... please go to " + url + " for futher instructions");
    }
}