Example usage for java.lang RuntimeException printStackTrace

List of usage examples for java.lang RuntimeException printStackTrace

Introduction

In this page you can find the example usage for java.lang RuntimeException printStackTrace.

Prototype

public void printStackTrace() 

Source Link

Document

Prints this throwable and its backtrace to the standard error stream.

Usage

From source file:br.com.senac.Bean.UsuarioBean.java

@PostConstruct
public void listar() {
    try {/*from w ww. j a v  a 2  s. com*/
        UsuarioDAO usuarioDAO = new UsuarioDAO();
        usuarios = usuarioDAO.listar();
    } catch (RuntimeException erro) {
        Messages.addFlashGlobalError("Ocorreu um erro ao tentar listar as Usurios");
        erro.printStackTrace();
    }
}

From source file:br.com.senac.Bean.UsuarioBean.java

public void popular() {
    try {/* w ww . j  a v  a2s  .  c  om*/
        if (estado != null) {
            CidadeDAO cidadeDAO = new CidadeDAO();
            cidades = cidadeDAO.buscaPorEstado(estado.getId());
        } else {
            cidades = new ArrayList<>();
        }
    } catch (RuntimeException erro) {
        Messages.addFlashGlobalError("Ocorreu um erro ao tentar filtrar as cidade");
        erro.printStackTrace();
    }
}

From source file:me.zhuoran.crawler4j.crawler.http.HttpClient.java

private HttpFetchResult doGet(final String threadName, final String defaultCharset, final URL url,
        final HttpGet req) {
    int retry = 0;//After the execute request failure of the number of retries
    StatusLine status = null;/* www.j  av  a 2s .  c  om*/
    HttpEntity entity = null;
    try {
        while (retry++ < 5) {
            try {
                HttpContext localContext = new BasicHttpContext();
                HttpResponse rsp = HttpConnectionManager.getHttpClient().execute(req, localContext);
                entity = rsp.getEntity();
                status = rsp.getStatusLine();
                if (status.getStatusCode() != HttpStatus.SC_OK) {
                    req.abort();
                    continue;
                }
                if (entity != null) {
                    logger.debug(threadName + " request get " + url.toFullString() + " " + rsp.getStatusLine());
                    return new HttpFetchResult(rsp, defaultCharset);
                } else {
                    req.abort();
                }
            } catch (IOException ex) {
                // In case of an IOException the connection will be released
                // back to the connection manager automatically
                continue;
            } catch (RuntimeException e) {
                req.abort();
                logger.error(threadName + " request " + url.toFullString() + " " + e.getMessage());
                e.printStackTrace();
                continue;
            } catch (Throwable e) {
                logger.error(threadName + " request " + url.toFullString() + " " + e.getMessage());
                e.printStackTrace();
            }
        }
    } finally {
        try {
            if (entity == null && req != null) {
                req.abort();
            }
        } catch (Exception e) {
            e.printStackTrace();
        }
    }
    logger.warn(threadName + " request get " + url.toFullString() + " " + status);
    return null;
}

From source file:net.sourceforge.pmd.ant.internal.PMDTaskImpl.java

private void handleError(RuleContext ctx, Report errorReport, RuntimeException pmde) {

    pmde.printStackTrace();
    project.log(pmde.toString(), Project.MSG_VERBOSE);

    Throwable cause = pmde.getCause();

    if (cause != null) {
        try (StringWriter strWriter = new StringWriter();
                PrintWriter printWriter = new PrintWriter(strWriter)) {
            cause.printStackTrace(printWriter);
            project.log(strWriter.toString(), Project.MSG_VERBOSE);
        } catch (IOException e) {
            project.log("Error while closing stream", e, Project.MSG_ERR);
        }/*from  w w  w.java  2s  . com*/
        if (StringUtils.isNotBlank(cause.getMessage())) {
            project.log(cause.getMessage(), Project.MSG_VERBOSE);
        }
    }

    if (failOnError) {
        throw new BuildException(pmde);
    }
    errorReport.addError(new Report.ProcessingError(pmde, ctx.getSourceCodeFilename()));
}

From source file:br.com.senac.Bean.UsuarioBean.java

public void excluir(ActionEvent evento) {
    try {// ww w .ja va2 s. com
        usuario = (Usuario) evento.getComponent().getAttributes().get("usuarioSelecionado");

        UsuarioDAO usuarioDAO = new UsuarioDAO();
        usuarioDAO.excluir(usuario);

        usuarios = usuarioDAO.listar();

        Messages.addGlobalInfo("Usurio removido com sucesso");
    } catch (RuntimeException erro) {
        Messages.addFlashGlobalError("Ocorreu um erro ao tentar remover o Usurio");
        erro.printStackTrace();
    }
}

From source file:br.com.senac.Bean.UsuarioBean.java

public void editar(ActionEvent evento) {
    try {//from w w w  .j a v  a  2s.  c o  m
        usuario = (Usuario) evento.getComponent().getAttributes().get("usuarioSelecionado");

        TipoDAO tipoDAO = new TipoDAO();
        tipos = tipoDAO.listar();
        CidadeDAO cidadeDAO = new CidadeDAO();
        cidades = cidadeDAO.listar();
    } catch (RuntimeException erro) {
        Messages.addFlashGlobalError("Ocorreu um erro ao tentar selecionar um Usurio");
        erro.printStackTrace();
    }
}

From source file:de.micromata.mgc.javafx.logging.LoggingController.java

@Override
public void initialize(URL location, ResourceBundle resources) {

    WebEngine engine = htmlView.getEngine();
    engine.getLoadWorker().stateProperty().addListener((ov, oldState, newState) -> {
        if (newState == javafx.concurrent.Worker.State.SUCCEEDED) {
            Document doc = engine.getDocument();
            //        if (guiWriteBuffer.isEmpty() == false) {
            //          List<LogWriteEntry> copy = new ArrayList<>(guiWriteBuffer);
            //          guiWriteBuffer.clear();
            //          addToGuiInGui(copy);
            //        }
        }/* w  w w  . j  a  v a  2  s  .  com*/
    });
    engine.setJavaScriptEnabled(true);

    StringBuilder html = new StringBuilder();

    String init = "  var logCounter = 0; \r\n" + "var loggingAdapter;\n"
            + "function ALogCallback(callback) { \n" + " this.callback = callback;\n"
            + " this.doCallback = function(entries) {this.callback(entries); }\n" + "};"
            + "function LogConsoleBackend(logViewer) {\r\n" + "  this.supportsPoll = false;\r\n"
            + "  this.supportsSearch = false;\r\n" + "  this.init = function(logViewer) {\r\n"
            + "  this.logViewer = logViewer;\n" + "   loggingAdapter.init(this);\n" + "  }\r\n"
            + "  this.logPoll = function(lastTime, callback) {\r\n"
            + "    loggingAdapter.logPoll(lastTime, new ALogCallback(callback));\r\n" + "  }\r\n"
            + "  this.getLoggingConfiguration = function() {\n"
            + "    return loggingAdapter.getLoggingConfiguration();\n" + "  };"
            + "  this.logSelect = function(logFormData, callback) {\r\n"
            + "    //console.debug('LogConsoleBackend.logSelect');\n"
            + "    loggingAdapter.logSelect(logFormData, new ALogCallback(callback));\n" + "  };\n"
            + "  this.logSelectAttributes = function(logId, callback) {\n"
            + "    loggingAdapter.logSelectAttributes(logId, new ALogCallback(callback));\n" + "  }\n" + "}"
            + "  function logProvider() {\r\n" + "    var item = {\r\n"
            + "      logTime : '2006-01-01 12:12',\r\n" + "      logLevel : 'Note',\r\n"
            + "      logMessage : 'Hello ' + ++logCounter,\r\n" + "      logAttributes : [ {\r\n"
            + "        typeName : \"AKey\",\r\n" + "        value : 'A value'\r\n" + "      }, {\r\n"
            + "        typeName : \"BKey\",\r\n" + "        value : 'B value'\r\n" + "      } ]\r\n"
            + "    };\r\n" + "    return [ item ];\r\n" + "  }\r\n" +

            "var logViewer = new GLogViewer({\r\n" + "    logListId : 'glogentries',\r\n"
            + "    formId : 'glogform',\r\n" + "    maxItems: 100,\r\n" + "    logPollTimeout: 1000,\r\n"
            + "    enableEmbeddedDebugger: false\n" + "\r\n" + "  });\n" + "window.logViewer = logViewer;\n";

    html.append("<html><head>").append(getHtmlHeader())

            .append("\n<script  type=\"text/javascript\">\n").append(init).append("\n</script>\n")
            .append("</head>").append("<body>\r\n");
    html.append(LogHtmlWindowServlet.getGLogHtmlForm());
    html.append("</body>");

    engine.loadContent(html.toString());
    engine.getLoadWorker().stateProperty().addListener((observable, oldValue, newValue) -> {
        try {

            JSObject window = (JSObject) engine.executeScript("window");
            window.setMember("loggingAdapter", loggingAdapter);

            engine.executeScript("console.debug = function(message){ loggingAdapter.jsdebug(message); };\n"
                    + "console.warn = function(message){ loggingAdapter.jswarn(message); };\n"
                    + "console.error = function(message){ loggingAdapter.jserror(message); }; console.debug('console redirect initialized');\n");
            //        JSObject logViewer = (JSObject) engine.executeScript("logViewer");
            //        logViewer.call("setBackend", loggingAdapter);
            engine.executeScript("logViewer.setBackend(new LogConsoleBackend());");
        } catch (RuntimeException ex) {
            ex.printStackTrace();
        }

    });
    INSTANCE = this;
    LoggingEventListenerRegistryService listenerRegisterService = LoggingServiceManager.get()
            .getLoggingEventListenerRegistryService();

    listenerRegisterService.registerListener(FxLogconsoleLogWriteEntryEventListener.class);
    listenerRegisterService.registerListener(FxLogconsoleLogRegisteredCategoryChangedEventListener.class);
    listenerRegisterService.registerListener(FxLogconsoleLogRegisteredLogAttributesChangedEventListener.class);
}

From source file:br.com.senac.Bean.UsuarioBean.java

public void novo() {
    try {//  w ww.ja  v a2s . com
        Date data = new Date();
        usuario = new Usuario();

        TipoDAO tipoDAO = new TipoDAO();
        tipos = tipoDAO.listar("descricao");
        EstadoDAO estadoDAO = new EstadoDAO();
        estados = estadoDAO.listar("nome");

        this.usuario.setDataCad(data);

        cidades = new ArrayList<Cidade>();
        //            CidadeDAO cidadeDAO = new CidadeDAO();
        //            cidades = cidadeDAO.listar();

    } catch (RuntimeException erro) {
        Messages.addFlashGlobalError("Ocorreu um erro ao gerar uma novo Usurio");
        erro.printStackTrace();
    }
}

From source file:name.vysoky.epub.Book.java

/**
 * Recursive function - find files with given extension and add these files to given list.
 * @param directory directory for scan//w ww.j a v a2s.c om
 * @param foundFiles found file list
 * @param extension filtered extension without dot
 */
private void findFilesWithExtension(File directory, List<File> foundFiles, String extension) {
    try {
        File[] files = directory.listFiles();
        if (files != null) {
            for (File file : files) {
                if (file.isDirectory())
                    findFilesWithExtension(file, foundFiles, extension);
                if (file.isFile() && FilenameUtils.isExtension(file.getName(), extension))
                    foundFiles.add(file);
            }
        }
    } catch (RuntimeException e) {
        e.printStackTrace();
    }
}

From source file:net.unicon.mycourses.portlet.MyCoursesController.java

public ModelAndView handleRenderRequestInternal(RenderRequest request, RenderResponse response)
        throws Exception {

    synchronized (this) {
        if (portletUID == Integer.MAX_VALUE) {
            portletUID = 0;//from w ww  .  jav a 2  s  . c o  m
        } else {
            portletUID++;
        }
        //System.out.println("!!! portletUID: " + portletUID);
    }

    Map model = new HashMap();
    String view = LIST_VIEW;
    PortletMode mode = request.getPortletMode();
    //WindowState state = request.getWindowState();

    String baseURL = null;
    String worksiteURL = "/login";
    PortletPreferences prefs = request.getPreferences();
    baseURL = prefs.getValue(BASE_URL, null);

    PortletURL refreshURL = response.createRenderURL();
    refreshURL.setParameter("randomValue", "" + System.currentTimeMillis() + portletUID);
    model.put("refreshURL", refreshURL);

    if (mode.toString().equals("view")) {

        Collection sites = new ArrayList();
        Collection terms = null;
        String membershipURL = null;
        String errorMessage = null;

        String selectedTerm = request.getParameter("selectedTerm");

        if (DEFAULT_TERM_SELECTION.equals(selectedTerm)) {

            // Set to null so the default term would be used
            selectedTerm = null;
        }

        try {

            SakaiServiceContext context = sakaiServiceContextFactory.contextFor(request);
            terms = sakaiSiteService.getTerms(context);

            if (selectedTerm == null) {
                Iterator termsIt = terms.iterator();
                while (termsIt.hasNext()) {
                    Term term = (Term) termsIt.next();
                    if (term.getIsDefault()) {
                        selectedTerm = term.getId();
                        break;
                    }
                }
            }

            if (selectedTerm == null) {
                sites = sakaiSiteService.getActiveSiteEnrollment(context);
            } else {
                sites = sakaiSiteService.getActiveSiteEnrollmentByTerm(context, selectedTerm);
                sites.addAll(sakaiSiteService.getActiveSiteEnrollmentByType(context, PROJECT_SITE_TYPE));
            }

            membershipURL = sakaiSiteService.getMembershipToolPageURL(context);

        } catch (SakaiServiceException sse) {
            logger.error("Sakai Service Exception", sse);
            sse.printStackTrace();
            errorMessage = sse.getErrorCode();
        } catch (RuntimeException rte) {
            logger.error("System Error", rte);
            rte.printStackTrace();
            errorMessage = DEFAULT_SYSTEM_ERROR;
        }

        if (errorMessage != null) {
            model.put("errorMessage", errorMessage);
        }
        if (membershipURL == null) {
            membershipURL = worksiteURL;
        }

        model.put("worksiteURL", worksiteURL);
        model.put("portletUID", Integer.valueOf(portletUID));
        model.put("membershipURL", membershipURL);
        model.put("baseURL", baseURL);
        model.put("selectedTerm", selectedTerm);
        model.put("terms", terms);
        model.put("sites", sites);
        model.put("siteCourse", COURSE_SITE_TYPE);
        model.put("siteProject", PROJECT_SITE_TYPE);

        view = LIST_VIEW;
    } else if (mode.toString().equals("help")) {
        view = HELP_VIEW;
    }

    return new ModelAndView(view, "model", model);
}