List of usage examples for java.lang Exception Exception
public Exception(Throwable cause)
From source file:Main.java
public static void printCallPathTop(String text) { try {/*from ww w. ja va2 s .co m*/ throw new Exception(text); } catch (Exception e) { StackTraceElement[] l = e.getStackTrace(); System.out.println( "DDTrace: [" + e.getLocalizedMessage() + "] " + l[1] + "\n" + l[2] + "\n" + l[l.length - 1]); } }
From source file:Main.java
public static String unescapeXml(String xml) throws Exception { if (xml == null) return null; StringBuilder b = new StringBuilder(); int i = 0;/* ww w. j a va2s. c o m*/ while (i < xml.length()) { if (xml.charAt(i) == '&') { StringBuilder e = new StringBuilder(); i++; while (xml.charAt(i) != ';') { e.append(xml.charAt(i)); i++; } if (e.toString().equals("lt")) b.append("<"); else if (e.toString().equals("gt")) b.append(">"); else if (e.toString().equals("amp")) b.append("&"); else if (e.toString().equals("quot")) b.append("\""); else if (e.toString().equals("mu")) b.append((char) 956); else throw new Exception("unknown XML entity \"" + e.toString() + "\""); } else b.append(xml.charAt(i)); i++; } return b.toString(); }
From source file:com.mirth.connect.manager.ServiceControllerFactory.java
public static ServiceController getServiceController() throws Exception { synchronized (ServiceController.class) { if (serviceController == null) { if (SystemUtils.IS_OS_WINDOWS) { serviceController = new WindowsServiceController(); } else if (SystemUtils.IS_OS_MAC) { serviceController = new MacServiceController(); } else if (SystemUtils.IS_OS_UNIX) { serviceController = new LinuxServiceController(); } else { throw new Exception("Operating system must be Windows, Mac, or Unix/Linux."); }//from www . j a va 2 s .c om } return serviceController; } }
From source file:Main.java
public static void addNodeToXml(String nodeParentXpathStr, String xmlFilePath, String nodeName, String value, Map<String, String> attr) throws Exception { Document doc = null;/*from w w w. j a va 2s. c o m*/ if (xmlFilePath == null || nodeParentXpathStr == null || nodeName == null || nodeParentXpathStr == null) throw new Exception("some parameters can not be null!"); doc = dombuilder.parse(new File(xmlFilePath)); Node pNode = (Node) xpath.compile(nodeParentXpathStr).evaluate(doc, XPathConstants.NODE); if (pNode == null) throw new Exception("can not find the node specified in nodeParentXpathStr!"); ; Element newNode = doc.createElement(nodeName); newNode.setTextContent(value); if (attr != null && !attr.isEmpty()) { for (String key : attr.keySet()) newNode.setAttribute(key, attr.get(key)); } pNode.appendChild(newNode); writeToXmlFile(doc, xmlFilePath); }
From source file:Main.java
/** * Print the call stack in the current point * @param text/* w ww. j a v a2s . c o m*/ */ public static void printCallPath(String text) { try { throw new Exception(text); } catch (Exception e) { e.printStackTrace(); } }
From source file:Main.java
public static long NonSearchingJavaToUnoType(Class<?> cls, boolean errorIfMissing) throws Throwable { String clsName = cls.getName(); Long unoTypePtr = unoTypes.get(clsName); if (unoTypePtr == null) { if (errorIfMissing) { String msg = "NonSearchingJavaToUnoType: Could not find uno type for " + clsName; throw new Exception(msg); } else {/* w ww .j a v a 2s. c o m*/ return 0L; } } return (long) unoTypePtr; }
From source file:Main.java
public static String getAttr(Node node, String name) throws DOMException { assert node != null; try {//w w w . j av a 2 s . co m NamedNodeMap attributes = node.getAttributes(); if (attributes == null) throw new Exception(""); Node attr = attributes.getNamedItem(name); if (attr == null) throw new Exception(""); String value = attr.getNodeValue(); if (value == null) throw new Exception(""); return value; } catch (Exception e) { throw new DOMException(DOMException.NOT_FOUND_ERR, String.format("attribute %s is missing at node %s", name, node.getNodeName())); } }
From source file:Main.java
/** * Write the <code>Document</code> in memory out to a standard XML file. * @param doc the <code>Document</code> object for the XML file to list * @param strFilePath the XML file to write to * @throws custom custom exception if file is not writeable * @throws ioe IOException if an error occurs on file creation * @throws fnfe FileNotFoundException if PrintWriter constructor fails *///from ww w. java 2 s. c o m public static void WriteXMLFile2(Document doc, String strFilePath) throws Exception { // open file for writing File file = new File(strFilePath); // ensure that file is writeable try { file.createNewFile(); if (!file.canWrite()) { throw new Exception("FileNotWriteable"); } } catch (IOException ioe) { throw ioe; } // create a PrintWriter to write the XML file to PrintWriter pw = null; try { pw = new PrintWriter(file); } catch (FileNotFoundException fnfe) { throw fnfe; } // write out the serialized form pw.print(getXMLListing(doc)); pw.close(); }
From source file:by.heap.remark.util.TestUtils.java
/** * Reads a resource into a string.//from w w w . j a v a 2 s. c o m * @param path Path to resource * @return String contents of resource */ public static String readResourceToString(String path) { String result; try { URL u = StringUtils.class.getResource(path); if (u == null) { throw new Exception("Resource not found"); } File f = FileUtils.toFile(u); if (!f.isFile()) { throw new Exception("Resource file does not exist or is not a file."); } result = FileUtils.readFileToString(f, "UTF-8"); if (result == null) { throw new Exception("Error reading resource file."); } } catch (Exception e) { e.printStackTrace(); result = "UNABLE TO LOAD RESOURCE " + path + ": " + e.getMessage(); } return result; }
From source file:Main.java
/** * Returns stacktrace of current thread represented as String * /* w ww . j a v a2 s . c om*/ * @return stacktrace of current thread represented as String */ public static String getStackTrace() { ByteArrayOutputStream baos = new ByteArrayOutputStream(); PrintStream printStream = new PrintStream(baos); // noinspection ThrowableInstanceNeverThrown new Exception("Stack trace").printStackTrace(printStream); printStream.close(); return new String(baos.toByteArray()); }