List of usage examples for java.lang Exception Exception
public Exception(Throwable cause)
From source file:com.hcspider.platypusjs.asynchttp.AsyncHTTPCallbacks.java
public static FutureCallback<HttpResponse> asCallback(BiConsumer<Object, Throwable> aWrapped) { return new FutureCallback<HttpResponse>() { @Override//from w w w . j a va 2 s . c o m public void completed(final HttpResponse response) { aWrapped.accept(response, null); } @Override public void failed(final Exception ex) { aWrapped.accept(null, ex); } @Override public void cancelled() { aWrapped.accept(null, new Exception("Async HTTP requst was cancelled.")); } }; }
From source file:Main.java
/** * Decode a variable. Variables are in the form $varname. If the incoming * expression is not a variable or is not recognised it is simply returned * verbatim./*from w ww.j a v a 2 s. c o m*/ * @param in The incoming attribute * @return String * @throws Exception */ private static String decode(String in) throws Exception { if (in != null && in.length() > 1 && in.charAt(0) == '$') { String key = in.substring(1); if (key.charAt(0) == '#') { // It's a class name and reflection job in the form $$full.class.name.member int lastIdx = key.lastIndexOf('.'); String member = key.substring(lastIdx + 1); String className = key.substring(1, lastIdx); Class<?> clazz = Class.forName(className); Field field = clazz.getDeclaredField(member); field.setAccessible(true); return String.valueOf(field.get(null)); } else { String val = vars.get(key); if (val == null) { throw new Exception("Unknown variable " + in); } else { return val; } } } else { return in; } }
From source file:Main.java
public static String XMLtoString(Document doc) throws Exception { try {/*from ww w . j a v a 2 s . co m*/ TransformerFactory tf = TransformerFactory.newInstance(); Transformer transformer; transformer = tf.newTransformer(); // below code to remove XML declaration // transformer.setOutputProperty(OutputKeys.OMIT_XML_DECLARATION, "yes"); StringWriter writer = new StringWriter(); transformer.transform(new DOMSource(doc), new StreamResult(writer)); return writer.getBuffer().toString(); } catch (TransformerException te) { throw new Exception(te.getMessageAndLocation()); } }
From source file:Stack.java
public T pop() throws Exception { if (top == -1) throw new Exception("Stack Empty"); return items[top--]; }
From source file:grandroid.geo.Geocoder.java
public static String convertAddress(double lat, double lng, boolean nation, boolean city, boolean district, boolean street) throws Exception { List<Address> adds = getFromLocation(lat, lng, 1); if (adds == null || adds.isEmpty()) { throw new Exception("no address can be found"); } else {//from w ww . ja v a 2 s .co m Address add = adds.get(0); StringBuilder sb = new StringBuilder(); if (nation) { sb.append(add.getCountryName()); } if (city) { sb.append(add.getAdminArea()); } if (district) { sb.append(add.getLocality()); } if (street) { sb.append(add.getAddressLine(0)); } return sb.toString(); } }
From source file:Main.java
/** * Converts a TimeML 1.2 file into a non-tagged TE3 TimeML input * get TE3-input, TE3input from tml/* ww w.j a v a 2s. c o m*/ * * @param tmlfile * @return */ public static String TML2TE3(String tmlfile) { String outputfile = null; try { String line; boolean textfound = false; String header = ""; String footer = ""; String text = ""; //process header (and dct)/text/footer outputfile = tmlfile + ".TE3input"; BufferedWriter te3writer = new BufferedWriter(new FileWriter(new File(outputfile))); BufferedReader TE3inputReader = new BufferedReader(new FileReader(new File(tmlfile))); try { // read out header while ((line = TE3inputReader.readLine()) != null) { if (line.length() > 0) { // break on TEXT if (line.matches(".*<TEXT>.*")) { textfound = true; break; } } header += line + "\n"; } if (!textfound) { throw new Exception("Premature end of file (" + tmlfile + ")"); } // read out text while ((line = TE3inputReader.readLine()) != null) { if (line.length() > 0) { // break on TEXT if (line.matches(".*</TEXT>.*")) { textfound = false; break; } } text += line.replaceAll("<[^>]*>", "") + "\n"; } if (textfound) { throw new Exception("Premature end of file (" + tmlfile + ")"); } // read out footer while ((line = TE3inputReader.readLine()) != null) { line = line.replaceAll("<(!--|[TSA]LINK|MAKEINSTANCE)[^>]*>", "").trim(); if (line.length() > 0) { footer += line + "\n"; } } te3writer.write(header + "\n"); te3writer.write("\n<TEXT>\n" + text + "</TEXT>\n"); te3writer.write(footer + "\n"); System.err.println("Processing file: " + tmlfile); } finally { if (TE3inputReader != null) { TE3inputReader.close(); } if (te3writer != null) { te3writer.close(); } } } catch (Exception e) { System.err.println("Errors found (TML_file_utils):\n\t" + e.toString() + "\n"); if (System.getProperty("DEBUG") != null && System.getProperty("DEBUG").equalsIgnoreCase("true")) { e.printStackTrace(System.err); } return null; } return outputfile; }
From source file:fr.certu.chouette.command.CommandParser.java
public static List<CommandArgument> parseArgs(String[] args) throws Exception { Map<String, List<String>> parameters = Command.globals; List<CommandArgument> commands = new ArrayList<CommandArgument>(); CommandArgument command = null;//w w w . j a va 2s . c om if (args.length == 0) { List<String> list = new ArrayList<String>(); list.add("true"); parameters.put("help", list); } for (int i = 0; i < args.length; i++) { if (args[i].startsWith("-")) { String key = args[i].substring(1).toLowerCase(); if (key.length() == 1) { String alias = Command.shortCuts.get(key); if (alias != null) key = alias; } if (key.equals("command")) { if (i == args.length - 1) { throw new Exception("missing command name"); } String name = args[++i]; if (name.startsWith("-")) { throw new Exception("missing command name before " + name); } command = new CommandArgument(name); parameters = command.getParameters(); commands.add(command); } else if (key.equals("file")) { if (i == args.length - 1) { throw new Exception("missing filename"); } String name = args[++i]; if (name.startsWith("-")) { throw new Exception("missing filename before " + name); } commands.addAll(parseFile(name)); } else { if (parameters.containsKey(key)) { throw new Exception("duplicate parameter : -" + key); } List<String> list = new ArrayList<String>(); if (i == args.length - 1 || args[i + 1].startsWith("-")) { list.add("true"); } else { while ((i + 1 < args.length && !args[i + 1].startsWith("-"))) { list.add(args[++i]); } } parameters.put(key, list); } } } return commands; }
From source file:gov.nih.nci.cadsr.cadsrpasswordchange.core.EmailHelper.java
public static String handleUserIDToken(String originalText, User user) throws Exception { String ret = originalText;//from w w w .j av a2 s.com if (user == null || user.getUsername() == null) { throw new Exception("User or user id is null or empty."); } if (originalText != null) { ret = StringUtils.replace(originalText, Constants.EMAIL_USER_ID_TOKEN, user.getUsername()); } return ret; }
From source file:Main.java
/** * Parse basic course data./*from w ww. j a v a2 s . com*/ */ private static void parseCourseData(final String line) throws Exception { final String[] nameTokens = line.split(":"); final String courseName = nameTokens[0].trim(); final int holeCount = Integer.parseInt(nameTokens[1].trim()); final String coursePars = nameTokens[2].trim(); v(" course name: " + courseName); v(" course hole counts: " + holeCount); v(" course pars: " + coursePars); final String[] parStrings = coursePars.split(","); if (holeCount != parStrings.length) { e("The specified hole count (" + holeCount + ") doesn't match the number of pars listed: (" + parStrings.length + "); aborting"); toast("The specified hole count (" + holeCount + ") doesn't match the number of pars listed: (" + parStrings.length + "); aborting"); throw new Exception("Bad hole count"); } final int[] pars = new int[holeCount]; for (int i = 0; i < holeCount; ++i) { pars[i] = Integer.parseInt(parStrings[i]); } courses.put(courseName, pars); }
From source file:com.netsteadfast.greenstep.sys.WsAuthenticateUtils.java
public static String getAuthKey(String currentId, String account) throws Exception { if (StringUtils.isBlank(currentId) || StringUtils.isBlank(account)) { throw new Exception("null key."); }/*from ww w. ja v a 2 s .c o m*/ return EncryptorUtils.encrypt(Constants.getEncryptorKey1(), Constants.getEncryptorKey2(), currentId + ";" + account + ";" + System.currentTimeMillis()); }