List of usage examples for java.lang Exception Exception
public Exception(Throwable cause)
From source file:Main.java
public static byte[] md5Digest(byte[] password) throws Exception { try {/*ww w .j a va2 s .com*/ MessageDigest alg = MessageDigest.getInstance("MD5"); alg.update(password); byte[] digest = alg.digest(); return digest; } catch (Exception e) { throw new Exception(e); } }
From source file:Main.java
public static void launch(Activity activity, String package_name) throws Exception { Intent intent = activity.getPackageManager().getLaunchIntentForPackage(package_name); if (intent != null) activity.startActivity(intent);//from www .ja v a 2 s.c o m else throw new Exception("Package Not Found"); }
From source file:Main.java
private static Field getSingletonField(Class<?> hostClas) { Field f = null;//from w w w . j ava 2 s . c o m try { f = hostClas.getDeclaredField("I"); if (!Modifier.isStatic(f.getModifiers())) throw new Exception("'I' field should be static." + f); f.setAccessible(true); } catch (Throwable ex) { } return f; }
From source file:Main.java
@Nullable private static StackTraceElement getCallOriginStackTraceElement() { StackTraceElement[] trace = new Exception("").getStackTrace(); StackTraceElement origin = null; final int length = trace.length; for (int i = 0; i < length; i++) { StackTraceElement element = trace[i]; String name = element.getClassName(); if (name.equals("sun.reflect.NativeMethodAccessorImpl")) { origin = trace[i - 1];/*from www . ja va 2 s . c om*/ break; } } return origin; }
From source file:Main.java
public static long save(long data, int start, int len, int value) throws Exception { if (start < 0 || len < 1 || start + len >= 64 || data < 0 || value < 0 || value > ((1 << len) - 1)) throw new Exception("Invalid Param!"); return ((value & (MASK_4F >> (63 - len))) << start) | (data & ((MASK_FF << (start + len)) | (MASK_4F >> (63 - start)))); }
From source file:Main.java
private static String bufferToString(BufferedReader br) throws Exception { StringBuffer sb = new StringBuffer(); try {/*from w ww . j a v a2 s .co m*/ for (String s = null; (s = br.readLine()) != null;) sb.append(s + "\n"); } catch (Exception e) { throw new Exception("Error reading the buffer: " + e.getMessage()); } return sb.toString(); }
From source file:Main.java
public static byte[] toMD5(byte[] bytes) throws Exception { try {// w ww .j a va 2 s .c om MessageDigest algorithm = MessageDigest.getInstance("MD5"); algorithm.reset(); return algorithm.digest(bytes); } catch (NoSuchAlgorithmException e) { throw new Exception(e); } }
From source file:Main.java
private static Node getSingleNodeElementByTagName(String tagName) throws Exception { NodeList list = getNodeList(tagName); Node node = null;/* ww w .j a v a2 s.c o m*/ if (list.getLength() > 0 && list.item(0).getNodeType() == Node.ELEMENT_NODE) { node = list.item(0); } else { throw new Exception("Xpath Query did not result in a Node element. Check your Xpath expression"); } return node; }
From source file:Main.java
public static String makeDir(String dirName) { String mRootPath = Environment.getExternalStorageDirectory().getAbsolutePath() + File.separator + dirName; try {// w w w . jav a 2 s .c o m File fRoot = new File(mRootPath); if (fRoot.exists() == false) { if (fRoot.mkdirs() == false) { throw new Exception(""); } } } catch (Exception e) { mRootPath = "-1"; } return mRootPath + "/"; }
From source file:Main.java
public static Node getSingleChildNode(Node p_node) throws Exception { NodeList l_list = null;// w w w .ja va2 s .c o m Node l_node = null; ArrayList<Node> l_a = null; l_list = p_node.getChildNodes(); if (l_list == null) { throw new Exception("XSD001: Unsupported / Invalid Element Type."); } l_a = new ArrayList<Node>(); for (int l_i = 0; l_i < l_list.getLength(); l_i++) { l_node = l_list.item(l_i); if (l_node.getNodeType() == Element.ELEMENT_NODE) { l_a.add(l_node); } } if (l_a.size() == 1) { l_node = l_a.get(0); } else { throw new Exception("XSD003: Unsupported / Invalid Element Type Structure."); } return l_node; }