List of usage examples for java.lang Exception Exception
public Exception()
From source file:com.mirth.connect.server.util.ConnectorUtil.java
public static ConnectionTestResponse testConnection(String host, int port, int timeout, String localAddr, int localPort) throws Exception { Socket socket = null;//from w w w. ja va2 s . c o m InetSocketAddress address = null; InetSocketAddress localAddress = null; try { address = new InetSocketAddress(host, port); if (StringUtils.isBlank(address.getAddress().getHostAddress()) || (address.getPort() < 0) || (address.getPort() > 65534)) { throw new Exception(); } } catch (Exception e) { return new ConnectionTestResponse(ConnectionTestResponse.Type.FAILURE, "Invalid host or port."); } if (localAddr != null) { try { localAddress = new InetSocketAddress(localAddr, localPort); if (StringUtils.isBlank(localAddress.getAddress().getHostAddress()) || (localAddress.getPort() < 0) || (localAddress.getPort() > 65534)) { throw new Exception(); } } catch (Exception e) { return new ConnectionTestResponse(ConnectionTestResponse.Type.FAILURE, "Invalid local host or port."); } } try { socket = new Socket(); if (localAddress != null) { try { socket.bind(localAddress); } catch (Exception e) { return new ConnectionTestResponse(ConnectionTestResponse.Type.FAILURE, "Could not bind to local address: " + localAddress.getAddress().getHostAddress() + ":" + localAddress.getPort()); } } socket.connect(address, timeout); String connectionInfo = socket.getLocalAddress().getHostAddress() + ":" + socket.getLocalPort() + " -> " + address.getAddress().getHostAddress() + ":" + address.getPort(); return new ConnectionTestResponse(ConnectionTestResponse.Type.SUCCESS, "Successfully connected to host: " + connectionInfo, connectionInfo); } catch (SocketTimeoutException ste) { return new ConnectionTestResponse(ConnectionTestResponse.Type.TIME_OUT, "Timed out connecting to host: " + address.getAddress().getHostAddress() + ":" + address.getPort()); } catch (Exception e) { return new ConnectionTestResponse(ConnectionTestResponse.Type.FAILURE, "Could not connect to host: " + address.getAddress().getHostAddress() + ":" + address.getPort()); } finally { if (socket != null) { socket.close(); } } }
From source file:com.eu.evaluation.server.ApplicationContextUtils.java
public static ApplicationContext getApplicationContext() { synchronized (ApplicationContextUtils.class) { while (applicationContext == null) { try { logger.debug("getApplicationContext, wait..."); ApplicationContextUtils.class.wait(60000); if (applicationContext == null) { logger.warn("Have been waiting for ApplicationContext to be set for 1 minute", new Exception()); }//from w ww . j ava 2s. c om } catch (InterruptedException ex) { logger.debug("getApplicationContext, wait interrupted"); } } return applicationContext; } }
From source file:Main.java
public Main() { setDefaultCloseOperation(DISPOSE_ON_CLOSE); setSize(400, 300);// w ww .j a v a 2s .c o m Exception ex = new Exception(); AttributeSet attr = null; StyledDocument doc = text.getStyledDocument(); for (StackTraceElement trace : ex.getStackTrace()) { try { doc.insertString(doc.getLength(), trace.toString() + '\n', attr); } catch (BadLocationException ex1) { ex1.printStackTrace(); } } getContentPane().add(new JScrollPane(text)); }
From source file:com.arellomobile.android.push.DeviceFeature2_5.java
static void sendPushStat(Context context, String hash) { final Map<String, Object> data = new HashMap<String, Object>(); data.putAll(RequestHelper.getSendPushStatData(context, hash, NetworkUtils.PUSH_VERSION)); Log.w(TAG, "Try To sent PushStat"); NetworkUtils.NetworkResult res = new NetworkUtils.NetworkResult(-1, null); Exception exception = new Exception(); for (int i = 0; i < NetworkUtils.MAX_TRIES; ++i) { try {/*from w ww . java 2 s. c o m*/ res = NetworkUtils.makeRequest(data, PUSH_STAT); if (200 == res.getResultCode()) { Log.w(TAG, "Send PushStat success"); return; } } catch (Exception e) { exception = e; } } Log.e(TAG, "ERROR: Try To sent PushStat " + exception.getMessage() + ". Response = " + res.getResultData(), exception); }
From source file:com.voidsearch.data.provider.facebook.GraphObjectFactory.java
/** * get object corresponding to given class, deserialized from response data * /* ww w.j ava 2 s. c o m*/ * @param name * @param data * @return * @throws Exception */ public static GraphObject getObject(String name, JSONObject data) throws Exception { if (name.equals("friends")) { return new FacebookUser(data); } else if (name.equals("likes")) { return new LikedEntry(data); } else if (name.equals("photos")) { return new PhotoEntry(data); } else if (name.equals("groups")) { return new GroupEntry(data); } else if (name.equals("home")) { return new NewsEntry(data); } else { throw new Exception(); } }
From source file:com.visural.domo.spring.Service.java
@Transactional public void runFail() throws Exception { throw new Exception(); }
From source file:com.zhangyue.zeus.util.BeanUtils.java
/** * map??BeanBean??mapkey??mapkey?OMIT_REG? * //from w w w . java 2 s .c om * @param <E> * @param cla * @param map * @return */ @SuppressWarnings({ "rawtypes" }) public static <E> E toBean(Class<E> cla, Map<String, Object> map) { // E obj = null; try { obj = cla.newInstance(); if (obj == null) { throw new Exception(); } } catch (Exception e) { LOG.error(",:" + cla); return null; } // ?mapkey Map<String, Object> newmap = new HashMap<String, Object>(); for (Map.Entry<String, Object> en : map.entrySet()) { newmap.put("set" + en.getKey().trim().replaceAll(OMIT_REG, "").toLowerCase(), en.getValue()); } // Method[] ms = cla.getMethods(); for (Method method : ms) { String mname = method.getName().toLowerCase(); if (mname.startsWith("set")) { Class[] clas = method.getParameterTypes(); Object v = newmap.get(mname); if (v != null && clas.length == 1) { try { method.invoke(obj, v); } catch (Exception e) { LOG.error("," + cla + "." + method.getName() + ".?" + clas[0] + ";:" + v.getClass()); } } } } return obj; }
From source file:Main.java
public static MatchResult matchSystemFile(final String pSystemFile, final String pPattern, final int pHorizon) throws Exception { InputStream in = null;// ww w.j a v a 2s . c om try { final Process process = new ProcessBuilder(new String[] { "/system/bin/cat", pSystemFile }).start(); in = process.getInputStream(); final Scanner scanner = new Scanner(in); final boolean matchFound = scanner.findWithinHorizon(pPattern, pHorizon) != null; if (matchFound) { return scanner.match(); } else { throw new Exception(); } } catch (final IOException e) { throw new Exception(e); } }
From source file:info.magnolia.test.TestUtil.java
public static String getCurrentTestMethodName() { final StackTraceElement[] stackTrace = new Exception().getStackTrace(); for (StackTraceElement ste : stackTrace) { if (ste.getMethodName().startsWith("test")) { return ste.getMethodName(); }// w w w .j av a2s .c om } throw new IllegalStateException( "Either you're not in a test at all, or you're calling this from a non-jUnit3 test."); }
From source file:com.moz.fiji.schema.util.Debug.java
/** * Returns a string representation of the current stack trace. * @return a string representation of the current stack trace. *//*www. j av a 2s . c om*/ public static String getStackTrace() { try { throw new Exception(); } catch (Exception exn) { return StringUtils.stringifyException(exn); } }