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:com.victorkifer.AndroidTemplates.api.Downloader.java

public static String textDownload(String url, int method, List<NameValuePair> params) throws Exception {
    StringBuilder builder = new StringBuilder();
    try {/*w  w w. j ava 2s.c  o  m*/
        HttpResponse httpResponse = null;

        switch (method) {
        case GET:
            httpResponse = makeHttpGetRequest(url, params);
            break;
        case POST:
            httpResponse = makeHttpPostRequest(url, params);
        }

        StatusLine statusLine = httpResponse.getStatusLine();
        int statusCode = statusLine.getStatusCode();
        if (statusCode == 200) {
            HttpEntity entity = httpResponse.getEntity();
            InputStream content = entity.getContent();
            BufferedReader reader = new BufferedReader(new InputStreamReader(content, "utf-8"));
            String line;
            while ((line = reader.readLine()) != null) {
                builder.append(line);
            }
        }
    } catch (UnsupportedEncodingException e) {
        Logger.e(TAG, e.getMessage());
        throw new Exception(AppUtils.getContext().getString(R.string.err_failed_download));
    } catch (ClientProtocolException e) {
        Logger.e(TAG, e.getMessage());
        throw new Exception(AppUtils.getContext().getString(R.string.err_failed_download));
    } catch (IOException e) {
        Logger.e(TAG, e.getMessage());
        throw new Exception(AppUtils.getContext().getString(R.string.err_failed_download));
    }

    Logger.i(TAG, builder.toString());

    return builder.toString();
}

From source file:com.thetdgroup.TextExtractionAdapter.java

public void initialize(final JSONObject configurationObject) throws Exception {
    if (configurationObject.has("adapter_configuration_file") == false) {
        throw new Exception("The adapter_configuration_file parameter was not found");
    }/* w w w . ja  v a  2  s.  c om*/

    //
    if (configurationObject.has("fuzein_connection_info")) {
        JSONObject jsonCommParams = configurationObject.getJSONObject("fuzein_connection_info");

        fuzeInCommunication.setFuzeInConnection(jsonCommParams.getString("service_url"),
                jsonCommParams.getInt("service_socket_timeout"),
                jsonCommParams.getInt("service_connection_timeout"),
                jsonCommParams.getInt("service_connection_retry"));
    }

    //
    parseAdapterConfiguration(configurationObject.getString("adapter_configuration_file"));
}

From source file:com.pokercompany.stringcalc.StringCalculator.java

public int add(String numbers) throws Exception {
    if (numbers == null) {
        throw new NullPointerException();
    }//from w ww.  java 2  s.c o m

    if (numbers.equals("")) {
        return 0;
    }

    if (!numbers.matches("-?[0-9]+([" + separator + "]-?[0-9]+)*[" + separator + "]?")) {
        throw new NumberFormatException("Bad character(s) in input string: " + numbers);
    }

    List<String> numbersList = Arrays.asList(numbers.split("(?<!\\" + separator + ")[" + separator + "]"));
    List<String> negativeNumbers = StringCalcUtil.getListWherePatternMatches(numbersList, "[-][0-9]+");

    if (negativeNumbers.size() > 0) {
        throw new Exception("Negative not allowed: " + StringUtils.join(negativeNumbers.iterator(), ","));
    }

    int sum = 0;
    for (String stringNumber : numbersList) {
        sum += Integer.valueOf(stringNumber);
    }

    return sum;
}

From source file:com.card.loop.xyz.service.LearningObjectService.java

public boolean acceptLO(LearningObjectDto lo) throws UnknownHostException, Exception {
    boolean ok = false;
    LearningObject model = dao.getLO(lo.getId());
    if (model != null) {
        model.setStatus(1);/*from  w  w w  .ja  va 2s .  com*/
        dao.acceptLO(model);
        ok = true;
    } else
        throw new Exception("LearningObject does not exist. ");
    return ok;

}

From source file:org.addhen.smssync.util.DataFormatUtil.java

public static String makeYAMLString(List<NameValuePair> pairs) throws Exception {
    //TODO: find a great open-source YAML parser
    throw new Exception("Not Implemented");
}

From source file:Main.java

/**
 * @param rawValue/*from   w ww.j a v  a 2 s .c  om*/
 * @return
 * @throws Exception 
 */
public static String decodeRawValueToSingleObjectId(String rawValue) throws Exception {
    String[] values = getSingleValue(rawValue);
    if (values[0].equals("o") && values[1].equals("n"))
        return null; // Reference to a null object
    String typeCode = values[0].substring(0);
    if (values[0].startsWith("r"))
        typeCode = values[0].substring(1);
    if ("c".equals(typeCode) | "o".equals(typeCode))
        return values[1];
    throw new Exception("Data type is not 'c' or 'o' (object ID), found '" + values[0] + "'");
}

From source file:io.servicecomb.foundation.common.utils.Log4jUtils.java

public static void init(List<String> locationPatterns) throws Exception {
    if (inited) {
        return;/*from   w  ww  . ja  v  a  2 s . com*/
    }

    synchronized (LOCK) {
        if (inited) {
            return;
        }

        PropertiesLoader loader = new PropertiesLoader(locationPatterns);
        Properties properties = loader.load();
        if (properties.isEmpty()) {
            throw new Exception("can not find resource " + locationPatterns);
        }

        PropertyConfigurator.configure(properties);
        inited = true;

        // ???merge?
        outputFile(loader.getFoundResList(), properties);
    }
}

From source file:top.lionxxw.bookingcar.domain.service.impl.UserServiceImpl.java

@Override
public void add(User user) throws Exception {
    if (userRepository.containsName(user.getName())) {
        throw new Exception(String.format("There is already a product with the name - %s", user.getName()));
    }//ww w .  ja  v a2 s .c  om

    if (user.getName() == null || "".equals(user.getName())) {
        throw new Exception("Booking name cannot be null or empty string.");
    }
    super.add(user);
}

From source file:Main.java

private static String[] getSingleValue(String rawValue) throws Exception {
    if (!rawValue.contains("_"))
        throw new Exception(
                "Raw value \"" + rawValue + "\" does not appear to be an INX raw value, expected '_'");
    //      logger.debug("getSingleValue(): raw value=\"" + rawValue + "\"");
    String[] tokens = rawValue.split("_"); // Should be two tokens
    if (tokens.length > 2)
        throw new Exception("Expected two items in tokenzied raw value, got " + tokens.length);
    if (tokens.length == 1) {
        // Means value was like "c_", which is valid and indicates and empty string.
        String[] newTokens = new String[2];
        newTokens[0] = tokens[0];/*  www. j a v  a 2s.  co m*/
        newTokens[1] = "";
        tokens = newTokens;
    }
    return tokens;
}

From source file:org.trustedanalytics.utils.errorhandling.ErrorLoggerTest.java

@Test
public void logErrorIsUsingGivenLogger() throws Exception {
    Logger logger = mock(Logger.class);
    Exception ex1 = new Exception("Some ex");
    ArgumentCaptor<String> capturedMessage = ArgumentCaptor.forClass(String.class);
    ArgumentCaptor<Throwable> capturedEx = ArgumentCaptor.forClass(Throwable.class);

    ErrorLogger.logError(logger, "Some message", ex1);

    verify(logger, times(1)).error(capturedMessage.capture(), capturedEx.capture());
    Assert.assertEquals("Some message", capturedMessage.getValue());
    Assert.assertEquals("Some ex", capturedEx.getValue().getMessage());
}