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.hangum.tadpole.sql.query.TadpoleSystemChecker.java

/**
 * ? ?  ? . //from www . j av a 2  s . c  o m
 * 
 * @return
 */
public static void checker() throws Exception {
    double dblJavaVersion = Double.parseDouble(JAVA_VERSION.substring(0, 3));

    // mac ? jvm 1.7 ?? ? .
    if (isMac()) {
        if (dblJavaVersion < 1.7d) {
            throw new Exception(String.format(Messages.TadpoleSystemChecker_2, "1.7.x")); //$NON-NLS-2$
        }

        //  ??  1.6 ??? . 
    } else {
        if (dblJavaVersion < 1.6d) {
            throw new Exception(String.format(Messages.TadpoleSystemChecker_2, "1.6.x")); //$NON-NLS-2$
        }
    }
}

From source file:edu.brandeis.cs.json.JsonProxy.java

public static String obj2json(Object obj) throws Exception {
    ObjectWriter ow = new ObjectMapper().writer();
    String json = null;/*from   www.  ja v a2s  .com*/
    try {
        json = ow.writeValueAsString(obj);
    } catch (JsonProcessingException e) {
        e.printStackTrace();
        throw new Exception(e);
    }
    return json;
}

From source file:Main.java

/**
 * Converts a {@link JSONArray} to an {@link ArrayList} of strings
 * @param jsonArray A JSON array that contains strings
 * @return A list of the strings contained in the JSON array
 *//*ww w. j ava 2 s .c  o  m*/
public static ArrayList<String> jsonArrayToList(JSONArray jsonArray) throws Exception {

    if (jsonArray.length() == 0)
        return new ArrayList<>();

    if (!(jsonArray.get(0) instanceof String))
        throw new Exception("Must pass in a json array with only string values");

    ArrayList<String> result = new ArrayList<>();
    for (int i = 0; i < jsonArray.length(); i++) {
        result.add(jsonArray.getString(i));
    }

    return result;
}

From source file:com.taobao.datasource.TaobaoDataSourceFactory.java

public static LocalTxDataSource createLocalTxDataSource(LocalTxDataSourceDO dataSourceDO,
        TxManager transactionManager, CachedConnectionManager cachedConnectionManager) throws Exception {
    if (null == dataSourceDO) {
        throw new Exception("dataSource config is Empty!");
    }/*from  w  w  w  .  j  a v a2  s . c  o  m*/
    LocalTxDataSource localTxDataSource = new LocalTxDataSource();
    //
    if (null != cachedConnectionManager) {
        localTxDataSource.setCachedConnectionManager(cachedConnectionManager);
    } else {
        localTxDataSource.setCachedConnectionManager(defaultCachedConnectionManager);
    }
    //
    if (null != transactionManager) {
        localTxDataSource.setTransactionManager(transactionManager);
    } else {
        localTxDataSource.setTransactionManager(defaultTransactionManager);
    }
    localTxDataSource.setBeanName(dataSourceDO.getJndiName());
    localTxDataSource.setUseJmx(dataSourceDO.isUseJmx());
    localTxDataSource.setBackgroundValidation(dataSourceDO.isBackgroundValidation());
    localTxDataSource.setBackGroundValidationMinutes(dataSourceDO.getBackgroundValidationMinutes());
    localTxDataSource.setBlockingTimeoutMillis(dataSourceDO.getBlockingTimeoutMillis());
    localTxDataSource.setCheckValidConnectionSQL(dataSourceDO.getCheckValidConnectionSQL());
    localTxDataSource.setConnectionProperties(dataSourceDO.getConnectionProperties());
    localTxDataSource.setConnectionURL(dataSourceDO.getConnectionURL());
    localTxDataSource.setDriverClass(dataSourceDO.getDriverClass());
    localTxDataSource.setExceptionSorterClassName(dataSourceDO.getExceptionSorterClassName());
    localTxDataSource.setIdleTimeoutMinutes(dataSourceDO.getIdleTimeoutMinutes());
    localTxDataSource.setMaxSize(dataSourceDO.getMaxPoolSize());
    localTxDataSource.setMinSize(dataSourceDO.getMinPoolSize());
    localTxDataSource.setNewConnectionSQL(dataSourceDO.getNewConnectionSQL());
    localTxDataSource.setNoTxSeparatePools(dataSourceDO.isNoTxSeparatePools());
    localTxDataSource.setPassword(dataSourceDO.getPassword());
    localTxDataSource.setPrefill(dataSourceDO.isPrefill());
    localTxDataSource.setPreparedStatementCacheSize(dataSourceDO.getPreparedStatementCacheSize());
    localTxDataSource.setQueryTimeout(dataSourceDO.getQueryTimeout());
    localTxDataSource.setSharePreparedStatements(dataSourceDO.isSharePreparedStatements());
    localTxDataSource.setTrackStatements(dataSourceDO.getTrackStatements());
    localTxDataSource.setTransactionIsolation(dataSourceDO.getTransactionIsolation());
    localTxDataSource.setTxQueryTimeout(dataSourceDO.isTxQueryTimeout());
    localTxDataSource.setUseFastFail(dataSourceDO.isUseFastFail());
    localTxDataSource.setUserName(dataSourceDO.getUserName());
    localTxDataSource.setValidateOnMatch(dataSourceDO.isValidateOnMatch());
    localTxDataSource.setValidConnectionCheckerClassName(dataSourceDO.getValidConnectionCheckerClassName());
    //
    String securityDomainName = dataSourceDO.getSecurityDomain();
    if (StringUtils.isNotBlank(securityDomainName)) {
        SecureIdentityLoginModule securityDomain = loginConfigFinder.get(securityDomainName);
        if (securityDomain != null) {
            localTxDataSource.setSecurityDomain(securityDomain);
        }
    }
    localTxDataSource.setCriteria(dataSourceDO.getCriteria());
    //
    localTxDataSource.init();
    return localTxDataSource;
}

From source file:org.nebula.service.core.HostAddress.java

public static String getLocalHost() throws Exception {

    Enumeration<NetworkInterface> interfaces = NetworkInterface.getNetworkInterfaces();
    while (interfaces.hasMoreElements()) {
        NetworkInterface current = interfaces.nextElement();

        if (!current.isUp() || current.isLoopback() || current.isVirtual()) {
            continue;
        }/* w w  w .  ja va  2s . c o  m*/
        Enumeration<InetAddress> addresses = current.getInetAddresses();
        while (addresses.hasMoreElements()) {
            InetAddress current_addr = addresses.nextElement();
            if (current_addr.isLoopbackAddress()
                    || !InetAddressUtils.isIPv4Address(current_addr.getHostAddress())) {
                continue;
            }
            return current_addr.getHostName();
        }
    }

    throw new Exception("Failed to get local hostname");
}

From source file:eu.optimis.treccommon.QueryDatabase.java

@SuppressWarnings("rawtypes")
public static String getManifest(String aserviceId) throws Exception {
    Session session = null;/*  www  .  j a  v  a  2 s . com*/

    try {
        session = HibernateUtil.getSessionFactory().openSession();
        // System.out.println("4");
    } catch (Exception e) {
        // System.out.println("3");

        logger.error("No database session could be retrieved");
        throw new Exception("No database session could be retrieved");
    }

    int i = 0;

    List SMList = new ArrayList<ManifestRaw>();

    // System.out.println("7");
    try {
        Criteria criteria = session.createCriteria(ManifestRaw.class);
        SMList = criteria.list();
        // System.out.println("sm list " + SMList.size());
    } catch (Exception e) {
        logger.error("No records found");
        throw new Exception("Excpetion thrown");
    }
    // System.out.println("8");
    session.close();
    // System.out.println("9");
    // System.out.println("14 kkk"+ SLAOffers.size());
    Iterator SMIterator = SMList.iterator();
    int k = 0;
    ManifestRaw[] sms = new ManifestRaw[SMList.size()];
    while (SMIterator.hasNext()) {

        ManifestRaw tempSMOffer = (ManifestRaw) SMIterator.next();

        sms[k] = new ManifestRaw();
        sms[k].setId(tempSMOffer.getId());

        sms[k].setServiceId(tempSMOffer.getServiceId());
        // System.out.println("serviceid " + serviceId);
        sms[k].setServiceManifest(tempSMOffer.getServiceManifest());
        sms[k].setIsBroker(tempSMOffer.isIsBroker());
        sms[k].setBrokerHost(tempSMOffer.getBrokerHost());
        sms[k].setBrokerPort(tempSMOffer.getBrokerPort());

        // System.out.println("tempRisk"+tempRisk);
        // sms[k] = new
        // ManifestRawObject(id,serviceId,servicemanifest,isBroker,brokerHost,
        // brokerPort);
        k++;
    }
    String sm_ret = null;
    for (i = 0; i < sms.length; i++) {
        if (sms[i].getServiceId().equalsIgnoreCase(aserviceId)) {
            // System.out.println("found");
            // System.out.println("service id = " + sms[i].getserviceId());
            // System.out.println("service mn = " +
            // sms[i].getserviceManifest());
            System.out.println("found");

            sm_ret = sms[i].getServiceManifest();
        }
    } // for
    return sm_ret;
}

From source file:io.apicurio.hub.core.js.OaiScriptEngineFactory.java

public static final ScriptEngine createScriptEngine(URL... jsUrls) throws Exception {
    logger.debug("Creating and initializing a Nashorn script engine.");
    long start = System.currentTimeMillis();
    ScriptEngine engine = new ScriptEngineManager().getEngineByName("nashorn");
    if (engine == null) {
        throw new Exception("Failed to create a Nashorn script engine!");
    }//  ww w.ja  v  a  2s  .c o m

    URL consoleJsUrl = OaiScriptEngineFactory.class.getClassLoader().getResource("js-lib/core-console.js");
    if (consoleJsUrl == null) {
        throw new Exception("Failed to load script: core-console.js");
    }
    URL oaiJsUrl = OaiScriptEngineFactory.class.getClassLoader().getResource("js-lib/OAI.umd.js");
    if (oaiJsUrl == null) {
        throw new Exception("Failed to load script: OAI.umd.js");
    }
    URL oaiCommandsJsUrl = OaiScriptEngineFactory.class.getClassLoader()
            .getResource("js-lib/OAI-commands.umd.js");
    if (oaiCommandsJsUrl == null) {
        throw new Exception("Failed to load script: OAI-commands.umd.js");
    }

    // Load the JS libraries into the engine
    engine.eval(IOUtils.toString(consoleJsUrl));
    engine.eval(IOUtils.toString(oaiJsUrl));
    engine.eval(IOUtils.toString(oaiCommandsJsUrl));
    for (URL jsUrl : jsUrls) {
        engine.eval(IOUtils.toString(jsUrl));
    }

    long end = System.currentTimeMillis();
    logger.debug("Initialized a Nashorn script engine in {} millis.", end - start);

    return engine;

}

From source file:lunarion.cluster.quickstart.BootstrapProcess.java

public static void main(String[] args) throws Exception {
    String zkConnectString = "localhost:2181";
    String clusterName = "storage-integration-cluster";
    String instanceName = "localhost_8905";
    String stateModelValue = "MasterSlave";
    int delay = 0;
    boolean skipZeroArgs = true;// false is for dev testing
    if (!skipZeroArgs || args.length > 0) {
        CommandLine cmd = processCommandLineArgs(args);
        zkConnectString = cmd.getOptionValue(zkServer);
        clusterName = cmd.getOptionValue(cluster);

        String host = cmd.getOptionValue(hostAddress);
        String portString = cmd.getOptionValue(hostPort);
        int port = Integer.parseInt(portString);
        instanceName = host + "_" + port;

        stateModelValue = cmd.getOptionValue(stateModel);
        if (cmd.hasOption(transDelay)) {
            try {
                delay = Integer.parseInt(cmd.getOptionValue(transDelay));
                if (delay < 0) {
                    throw new Exception("delay must be positive");
                }//  w w w .  ja  v a2s.c om
            } catch (Exception e) {
                e.printStackTrace();
                delay = 0;
            }
        }
    }
    // Espresso_driver.py will consume this
    System.out.println("Starting Process with ZK:" + zkConnectString);

    BootstrapProcess process = new BootstrapProcess(zkConnectString, clusterName, instanceName, stateModelValue,
            delay);

    process.start();
    Thread.currentThread().join();
}

From source file:com.sg.rest.controllers.TestController.java

@RequestMapping(value = RequestPath.TEST_REQUEST_THROW_EXCEPTION, method = RequestMethod.GET)
public void pingException() throws Exception {
    throw new Exception("Error");
}

From source file:geotag.example.sbickt.SbicktAPI.java

public static void login(List<NameValuePair> userData) throws Exception {
    HttpHelper httpConnection = HttpHelper.getInstance(Properties.getUrl() + Properties.URL_FOLDER_LOGIN);

    if (!httpConnection.POSTRequest(userData)) {
        throw new Exception("SbicktAPI -> login: Failed to login");
    }/* w  ww . j  ava 2s .  co  m*/
}