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.asakusafw.runtime.report.CommonsLoggingReport.java

@Override
public void report(Level level, String message) {
    if (level == Level.ERROR) {
        if (LOG.isErrorEnabled()) {
            LOG.error(message, new Exception("error"));
        }//w  ww  .  j a  va 2  s . co m
    } else if (level == Level.WARN) {
        if (LOG.isWarnEnabled()) {
            LOG.warn(message, new Exception("warn"));
        }
    } else if (level == Level.INFO) {
        LOG.info(message);
    } else {
        LOG.fatal(MessageFormat.format("Unknown level \"{0}\": {1}", level, message));
    }
}

From source file:gestores.PoolDeConexiones.java

protected void pedirConexion() throws Exception {
    if (conexion == null) {
        try {//from www .  j av a  2  s  . co  m
            BasicDataSource basicDataSource = new BasicDataSource();
            basicDataSource.setDriverClassName("com.mysql.jdbc.Driver");
            basicDataSource.setUrl("jdbc:mysql://localhost:3306/osg");
            basicDataSource.setUsername("root");
            basicDataSource.setPassword("root");
            basicDataSource.setMaxActive(20);
            basicDataSource.setMaxIdle(2);
            conexion = basicDataSource.getConnection();
            conexion.setAutoCommit(false);
        } catch (SQLException e) {
            throw new Exception(e.getMessage());
        }
    }
}

From source file:net.fabricmc.installer.installer.MultiMCInstaller.java

public static void install(File mcDir, String version, IInstallerProgress progress) throws Exception {
    File instancesDir = new File(mcDir, "instances");
    if (!instancesDir.exists()) {
        throw new FileNotFoundException(Translator.getString("install.multimc.notFound"));
    }/* ww w. ja v a  2 s. c om*/
    progress.updateProgress(Translator.getString("install.multimc.findInstances"), 10);
    String mcVer = version.split("-")[0];
    List<File> validInstances = new ArrayList<>();
    for (File instanceDir : instancesDir.listFiles()) {
        if (instanceDir.isDirectory()) {
            if (isValidInstance(instanceDir, mcVer)) {
                validInstances.add(instanceDir);
            }
        }
    }
    if (validInstances.isEmpty()) {
        throw new Exception(Translator.getString("install.multimc.noInstances").replace("[MCVER]", mcVer));
    }
    List<String> instanceNames = new ArrayList<>();
    for (File instance : validInstances) {
        instanceNames.add(instance.getName());
    }
    String instanceName = (String) JOptionPane.showInputDialog(null,
            Translator.getString("install.multimc.selectInstance"),
            Translator.getString("install.multimc.selectInstance"), JOptionPane.QUESTION_MESSAGE, null,
            instanceNames.toArray(), instanceNames.get(0));
    if (instanceName == null) {
        progress.updateProgress(Translator.getString("install.multimc.canceled"), 100);
        return;
    }
    progress.updateProgress(
            Translator.getString("install.multimc.installingInto").replace("[NAME]", instanceName), 25);
    File instnaceDir = null;
    for (File instance : validInstances) {
        if (instance.getName().equals(instanceName)) {
            instnaceDir = instance;
        }
    }
    if (instnaceDir == null) {
        throw new FileNotFoundException("Could not find " + instanceName);
    }
    File patchesDir = new File(instnaceDir, "patches");
    if (!patchesDir.exists()) {
        patchesDir.mkdir();
    }
    File fabricJar = new File(patchesDir, "Fabric-" + version + ".jar");
    if (!fabricJar.exists()) {
        progress.updateProgress(Translator.getString("install.client.downloadFabric"), 30);
        FileUtils.copyURLToFile(new URL("http://maven.modmuss50.me/net/fabricmc/fabric-base/" + version
                + "/fabric-base-" + version + ".jar"), fabricJar);
    }
    progress.updateProgress(Translator.getString("install.multimc.createJson"), 70);
    File fabricJson = new File(patchesDir, "fabric.json");
    if (fabricJson.exists()) {
        fabricJson.delete();
    }
    String json = readBaseJson();
    json = json.replaceAll("%VERSION%", version);

    ZipFile fabricZip = new ZipFile(fabricJar);
    ZipEntry dependenciesEntry = fabricZip.getEntry("dependencies.json");
    String fabricDeps = IOUtils.toString(fabricZip.getInputStream(dependenciesEntry), Charset.defaultCharset());
    json = json.replace("%DEPS%", stripDepsJson(fabricDeps.replace("\n", "")));
    FileUtils.writeStringToFile(fabricJson, json, Charset.defaultCharset());
    fabricZip.close();
    progress.updateProgress(Translator.getString("install.success"), 100);
}

From source file:com.ming800.organization.controller.BigUserFormHandler.java

@Override
public ModelMap handle(ModelMap modelMap, HttpServletRequest request) throws Exception {

    String id = request.getParameter("id");
    if (!userLimit() && id == null) {
        throw new Exception("???");
    }/* w w w  .j  a  v a2 s .  c o m*/
    Object object = modelMap.get("object");

    Do tempDo = doManager.getDoByQueryModel("formDefinedUser");

    if (tempDo != null) {
        Page tempPage = tempDo.getPageList().get(0);

        MethodCache methodCache = new MethodCache();
        methodCache.init(tempDo, tempPage);

        modelMap.put("jsonData", xdoManager.viewPageJson(tempPage, object, methodCache));
    }

    return modelMap; //To change body of implemented methods use File | Settings | File Templates.
}

From source file:crittercism.CrittercismModuleModule.java

private static Exception createException(String name, String reason, String stackTrace) {
    Exception ex = new Exception(reason);
    if (stackTrace != null) {
        String[] stackObjs = stackTrace.split("\n");

        int nLength = stackObjs.length;
        StackTraceElement[] elements = new StackTraceElement[nLength];

        for (int nI = 0; nI < nLength; nI++) {
            elements[nI] = new StackTraceElement("Unity3D", stackObjs[nI], "", -1);
        }/*from ww  w  . j a va  2 s  .c o m*/
        ex.setStackTrace(elements);
    }
    ;

    return ex;
}

From source file:com.hangum.tadpole.rdb.core.editors.main.utils.plan.CubridExecutePlanUtils.java

/**
 * cubrid execute plan/*w  w w.j a va2s . c om*/
 * 
 * @param userDB
 * @param reqQuery
 * @return
 * @throws Exception
 */
public static String plan(UserDBDAO userDB, final RequestQuery reqQuery) throws Exception {
    String sql = reqQuery.getSql();
    if (!sql.toLowerCase().startsWith("select")) {
        logger.error("[cubrid execute plan ]" + sql);
        throw new Exception("This statment not select. please check.");
    }
    Connection conn = null;
    ResultSet rs = null;
    PreparedStatement pstmt = null;

    try {
        conn = TadpoleSQLManager.getInstance(userDB).getDataSource().getConnection();
        conn.setAutoCommit(false); //     auto commit? false  .

        sql = StringUtils.trim(sql).substring(6);
        if (logger.isDebugEnabled())
            logger.debug("[qubrid modifying query]" + sql);
        sql = "select " + RECOMPILE + sql;

        pstmt = conn.prepareStatement(sql);
        if (reqQuery.getSqlStatementType() == SQL_STATEMENT_TYPE.PREPARED_STATEMENT) {
            final Object[] statementParameter = reqQuery.getStatementParameter();
            for (int i = 1; i <= statementParameter.length; i++) {
                pstmt.setObject(i, statementParameter[i - 1]);
            }
        }
        ((CUBRIDStatement) pstmt).setQueryInfo(true);
        rs = pstmt.executeQuery();

        String plan = ((CUBRIDStatement) pstmt).getQueryplan(); //  ?    .
        if (logger.isDebugEnabled())
            logger.debug("cubrid plan text : " + plan);

        return plan;
    } finally {
        if (rs != null)
            rs.close();
        if (pstmt != null)
            pstmt.close();
        if (conn != null)
            conn.close();
    }
}

From source file:nc.noumea.mairie.appock.util.StockSpreadsheetImporter.java

public static List<String> importFromXls(Service service, StockService stockService, InputStream in)
        throws Exception {

    List<String> warnings = new ArrayList<>();
    try {//from   ww  w  .  j  a v  a 2s  .co  m
        XSSFWorkbook workbook = new XSSFWorkbook(in);
        XSSFSheet worksheet = workbook.getSheet(NOM_ONGLET_CLASSEUR);

        if (worksheet == null) {
            throw new Exception("L'onglet '" + NOM_ONGLET_CLASSEUR + "' du classeur est introuvable");
        }

        for (int i = 1; i < worksheet.getLastRowNum() + 1; i++) {
            try {
                traiterLigne(i, worksheet, service, stockService);
            } catch (ImportExcelException e) {
                warnings.add(e.getMessage());
            }
        }
    } finally {
        in.close();
    }
    return warnings;
}

From source file:Main.java

/**
 * Given a value that should contain a single string or enum key, return the string.
 * @param rawValue/*from  www.  j ava 2  s .  c o  m*/
 * @return
 */
public static String decodeRawValueToSingleString(String rawValue) throws Exception {
    String[] values = getSingleValue(rawValue);
    //      logger.debug("values[].length=" + values.length);
    String dataType = values[0];
    if (dataType.startsWith("r"))
        dataType = dataType.substring(1);
    if ("c".equals(dataType) || "e".equals(dataType) || "k".equals(dataType))
        return values[1].replace("~sep~", " ");
    throw new Exception(
            "Data type is not 'c' (character), 'e' (enum) or 'k' (string key), found '" + values[0] + "'");
}

From source file:de.ingrid.interfaces.csw.tools.IdfUtils.java

/**
 * Extract the idf document from the given record. Throws an exception
 * if there is not idf content./*from   w ww  .ja  va2s  . co m*/
 * @param record
 * @return Document
 * @throws Exception
 */
public static Document getIdfDocument(Record record) throws Exception {
    String content = IdfTool.getIdfDataFromRecord(record);
    if (content != null) {
        try {
            return StringUtils.stringToDocument(content);
        } catch (Throwable t) {
            log.error("Error transforming record to DOM: " + content, t);
            throw new Exception(t);
        }
    } else {
        throw new IOException("Document contains no IDF data.");
    }
}

From source file:com.founder.fix.fixflow.explorer.util.FileHandle.java

public static void whenUploadFileBindParameter(HttpServletRequest request, HttpServletResponse response)
        throws Exception {
    try {// ww w  .  j  a  v a2 s . c  om
        fi.clear();
        fi.removeAll(fi);
        Iterator<FileItem> iterator = createFactory(request, response);
        while (iterator.hasNext()) {
            FileItem fileItem = (FileItem) iterator.next();
            if (fileItem.isFormField()) { // ??????
                String name = fileItem.getFieldName(); // inputname
                String value = fileItem.getString(); // input?value
                request.setAttribute(filterEncoding(name), filterEncoding(value));
            } else {
                fi.add(fileItem);
            }
        }
    } catch (Exception e) {
        e.printStackTrace();
        throw new Exception("??!");
    }
}