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:hmatalonga.greenhub.managers.sampling.DataEstimator.java

@Override
public void onReceive(Context context, Intent intent) {
    if (context == null) {
        LOGE(TAG, "Error, context is null");
        return;/*  www . j  a  v  a  2 s  . co  m*/
    }

    if (intent == null) {
        LOGE(TAG, "Data Estimator error, received intent is null");
        return;
    }

    LOGI(TAG, "onReceive action => " + intent.getAction());

    if (intent.getAction().equals(Intent.ACTION_BATTERY_CHANGED)) {
        try {
            level = intent.getIntExtra(BatteryManager.EXTRA_LEVEL, -1);
            scale = intent.getIntExtra(BatteryManager.EXTRA_SCALE, -1);
            health = intent.getIntExtra(BatteryManager.EXTRA_HEALTH, 0);
            plugged = intent.getIntExtra(BatteryManager.EXTRA_PLUGGED, 0);
            present = intent.getExtras().getBoolean(BatteryManager.EXTRA_PRESENT);
            status = intent.getIntExtra(BatteryManager.EXTRA_STATUS, 0);
            technology = intent.getExtras().getString(BatteryManager.EXTRA_TECHNOLOGY);
            temperature = ((float) intent.getIntExtra(BatteryManager.EXTRA_TEMPERATURE, 0)) / 10;
            voltage = ((float) intent.getIntExtra(BatteryManager.EXTRA_VOLTAGE, 0)) / 1000;
        } catch (RuntimeException e) {
            e.printStackTrace();
        }

        if (SettingsUtils.isBatteryAlertsOn(context)) {
            // Notify for temperature alerts...
            if (temperature > 45) {
                Notifier.batteryHighTemperature(context);
            } else if (temperature <= 45 && temperature > 35) {
                Notifier.batteryWarningTemperature(context);
            }
        }

        if (SettingsUtils.isPowerIndicatorShown(context)) {
            Notifier.updateStatusBar(context);
        }
    }

    // On some phones, scale is always 0.
    if (scale == 0)
        scale = 100;

    if (level > 0) {
        Inspector.setCurrentBatteryLevel(level, scale);

        // Location updates disabled for now
        // requestLocationUpdates();

        // Update last known location...
        // if (lastKnownLocation == null) {
        //    lastKnownLocation = LocationInfo.getLastKnownLocation(context);
        // }

        Intent service = new Intent(context, DataEstimatorService.class);
        service.putExtra("OriginalAction", intent.getAction());
        service.fillIn(intent, 0);
        service.putExtra("distance", distance);

        EventBus.getDefault().post(new BatteryLevelEvent(level));

        startWakefulService(context, service);
    }
}

From source file:com.asociate.dao.UsuarioDAO.java

/**
 *
 * @param query//from   w  ww  .j a va2s.c  o m
 * @param idUsuario
 * @return
 */
public List<Usuario> buscarContacto(String query, Long idUsuario) {
    Session sesion = HibernateUtil.getSessionFactory().openSession();
    List<Usuario> salida = new ArrayList<>();
    try {
        Query qu = sesion.createSQLQuery("Select U.* from usuario U "
                + "join amistad A on A.id_amigo=U.id_usuario" + " where A.id_origen = :idUsuario  and "
                + "A.id_amigo in(" + "(Select P.id_usuario from persona P where lower(nombre) like lower('%"
                + query + "%') " + " or lower(apellidop) like lower('%" + query + "%')) union "
                + "(Select S.id_usuario from asociacion S where lower(razonsocial) like lower('%" + query
                + "%') )" + ")");
        qu.setParameter("idUsuario", idUsuario);
        salida = qu.list();

    } catch (RuntimeException e) {
        e.printStackTrace();
    } finally {
        sesion.flush();
        sesion.close();
    }
    return salida;
}

From source file:org.openlegacy.tools.maven.SessionRunner.java

public void execute() throws MojoExecutionException {
    int port = (Integer) getProperty(PORT, defaultPort);

    Server server = new Server(port);
    Handler handler = new AbstractHandler() {

        public void handle(String target, HttpServletRequest request, HttpServletResponse response,
                int dispatch) throws IOException, ServletException {

            try {
                initApplicationContext();

                String uri = request.getRequestURI();
                if (uri.contains(".js")) {
                    handleJsFiles(request, response, uri);
                    return;
                }/*from   w w  w  . j  a  va2 s . co  m*/

                if (uri.contains("sequence")) {
                    response.getWriter().write(getTerminalSession().getSequence().toString());
                    ((Request) request).setHandled(true);
                    return;
                }

                if (uri.contains("logoff")) {
                    handleLogoff(response);
                    ((Request) request).setHandled(true);
                    return;
                }
                String flip = request.getParameter("flip");
                if (flip != null) {
                    getTerminalSession().getSnapshot();
                    getTerminalSession().flip();
                }
                if (request.getMethod().equalsIgnoreCase("POST")) {
                    handlePost(request);
                }
                handleHtmlRendering(request, response);
            } catch (RuntimeException e) {
                e.printStackTrace();
                throw (e);
            }
        }
    };

    server.setHandler(handler);
    try {
        server.start();
        // wait forever until maven is stopped

        openBrowser(port);

        while (true) {
            Thread.sleep(10000);
        }

    } catch (Exception e1) {
        throw (new RuntimeException(e1));
    }

}

From source file:Replier.java

/**
 * Handle the message.//from w w  w .ja v a  2s  . co m
 * (as specified in the javax.jms.MessageListener interface).
 *
 * IMPORTANT NOTES:
 * (1)We must follow the design paradigm for JMS
 *    synchronous requests.  That is, we must:
 *     - get the message
 *     - look for the header specifying JMSReplyTo
 *     - send a reply to the queue specified there.
 *    Failing to follow these steps might leave the originator
 *    of the request waiting forever.
 * (2)Unlike the 'Talk' sample and others using an asynchronous
 *    message listener, it is possible here to use ONLY
 *    ONE SESSION because the messages being sent are sent from
 *    the same thread of control handling message delivery. For
 *    more information see the JMS spec v1.0.2 section 4.4.6.
 *
 * OPTIONAL BEHAVIOR: The following actions taken by the
 * message handler represent good programming style, but are
 * not required by the design paradigm for JMS requests.
 *   - set the JMSCorrelationID (tying the response back to
 *     the original request.
 *   - use transacted session "commit" so receipt of request
 *     won't happen without the reply being sent.
 *
 */
public void onMessage(javax.jms.Message aMessage) {
    try {
        // Cast the message as a text message.
        javax.jms.TextMessage textMessage = (javax.jms.TextMessage) aMessage;

        // This handler reads a single String from the
        // message and prints it to the standard output.
        try {
            String string = textMessage.getText();
            System.out.println("[Request] " + string);

            // Check for a ReplyTo Queue
            javax.jms.Queue replyQueue = (javax.jms.Queue) aMessage.getJMSReplyTo();
            if (replyQueue != null) {
                // Send the modified message back.
                javax.jms.TextMessage reply = session.createTextMessage();
                if (imode == UPPERCASE)
                    reply.setText("Uppercasing-" + string.toUpperCase());
                else
                    reply.setText("Lowercasing-" + string.toLowerCase());
                reply.setJMSCorrelationID(aMessage.getJMSMessageID());
                replier.send(replyQueue, reply);
                session.commit();
            }
        } catch (javax.jms.JMSException jmse) {
            jmse.printStackTrace();
        }
    } catch (java.lang.RuntimeException rte) {
        rte.printStackTrace();
    }
}

From source file:org.dbpedia.spotlight.parser.WikiXMLParser.java

@Override
public void endElement(String uri, String name, String qName) throws SAXException {
    try {/*from   w w w.j av  a2  s .c om*/
        if (fArticle == null) {
            if (fSiteinfo != null) {
                if (WIKIPEDIA_NAMESPACE.equals(qName) && fNamespaceKey != null) {
                    fSiteinfo.addNamespace(fNamespaceKey, getString());
                } else if ("sitename".equals(qName)) {
                    fSiteinfo.setSitename(getString());
                } else if ("base".equals(qName)) {
                    fSiteinfo.setBase(getString());
                } else if ("generator".equals(qName)) {
                    fSiteinfo.setGenerator(getString());
                } else if ("case".equals(qName)) {
                    fSiteinfo.setCharacterCase(getString());
                }
            }
        } else {
            if (WIKIPEDIA_PAGE.equals(qName)) {
            } else if (WIKIPEDIA_TEXT.equals(qName)) {
                fArticle.setText(getString());
                fArticleFilter.process(fArticle, fSiteinfo);
                // emit(wikiText);
            } else if (WIKIPEDIA_TITLE.equals(qName)) {
                fArticle.setTitle(getString(), fSiteinfo);
            } else if (WIKIPEDIA_TIMESTAMP.equals(qName)) {
                fArticle.setTimeStamp(getString());
            } else if (!fRevision && WIKIPEDIA_ID.equals(qName)) {
                // get the id from wiki page, not the id from the revision
                fArticle.setId(getString());
            }
        }
        fData = null;
        // fAttributes = null;

    } catch (RuntimeException re) {
        re.printStackTrace();
    }
}

From source file:com.asociate.dao.UsuarioDAO.java

/**
 *
 * @param busqueda/*from   w w w. j  a va2s  .  c  o  m*/
 * @return
 */
public List<Usuario> buscarUsuarios(String busqueda) {
    List<Usuario> salida = new ArrayList();
    Session sesion = HibernateUtil.getSessionFactory().openSession();

    try {
        Query qu = sesion.createQuery("Select U from Usuario U join fetch U.persona P" + " where ("
        //+ " lower(A.razonsocial) like lower('%"+busqueda+"%') or "
                + " lower(P.nombre) like lower('%" + busqueda + "%') or " + " lower(P.apellidop) like lower('%"
                + busqueda + "%') or " + " lower(P.alias) like lower('%" + busqueda + "%') or "
                + " lower(P.apellidom) like lower('%" + busqueda + "%')) and"
                + " U.bloqueado = 'N' and U.confirmado = 'S' ");

        salida = qu.list();

    } catch (RuntimeException e) {
        e.printStackTrace();
    } finally {
        sesion.flush();
        sesion.close();
    }

    return salida;
}

From source file:com.asociate.dao.UsuarioDAO.java

/**
 *
 * @param amigos/*from ww w  .j  ava 2  s  .c om*/
 * @return
 */
public List<Usuario> getAmigosDeLista(List<Amistad> amigos) {
    List<Usuario> salida = new ArrayList();
    Session sesion = HibernateUtil.getSessionFactory().openSession();
    StringBuffer sb = new StringBuffer();
    for (Amistad am : amigos) {
        sb.append(" ");
        sb.append(am.getIdAmigo());
        sb.append(" ,");
    }
    sb.delete(sb.lastIndexOf(",") - 1, sb.length());
    try {
        Query qu = sesion.createQuery("Select U from Usuario U where U.persona.idPersona in(:list)");
        qu.setParameter("list", sb.toString());
        salida = qu.list();

    } catch (RuntimeException e) {
        e.printStackTrace();
    } finally {
        sesion.flush();
        sesion.close();
    }
    return salida;
}

From source file:TransactedTalk.java

/**
 * Handle the message//ww w .j  a v  a 2s.c o m
 * (as specified in the javax.jms.MessageListener interface).
 */
public void onMessage(javax.jms.Message aMessage) {
    try {
        // Cast the message as a text message.
        javax.jms.TextMessage textMessage = (javax.jms.TextMessage) aMessage;

        // This handler reads a single String from the
        // message and prints it to the standard output.
        try {
            String string = textMessage.getText();
            System.out.println(string);
        } catch (javax.jms.JMSException jmse) {
            jmse.printStackTrace();
        }
    } catch (java.lang.RuntimeException rte) {
        rte.printStackTrace();
    }
}

From source file:com.ethlo.geodata.restdocs.AbstractJacksonFieldSnippet.java

protected ObjectNode getSchema(Operation operation, final Class<?> pojo, boolean isResponse) {
    try {//from   w w w .  j  a v a  2  s  . c om
        final ObjectNode schema = (ObjectNode) generator.generateSchema(pojo, isResponse);

        final Collection<FieldDescriptor> fieldDescriptors = createFieldDescriptors(operation, pojo);

        // Add field descriptions on top of JSON schema
        fieldDescriptors.forEach(desc -> {
            final String[] pathArr = org.apache.commons.lang3.StringUtils.split(desc.getPath(), '.');
            final Iterator<String> path = Arrays.asList(pathArr).iterator();
            final ObjectNode definitionsNode = schema.get("definitions") != null
                    ? (ObjectNode) schema.get("definitions")
                    : schema.objectNode();
            handleSchema(pojo, schema, definitionsNode, desc, path);
        });

        allSchemas.put(pojo, schema);
        ((ObjectNode) schema).remove("definitions");

        return schema;
    } catch (RuntimeException exc) {
        exc.printStackTrace();
        throw exc;
    }
}

From source file:br.com.railsos.os.bean.AgendamentoBean.java

@PostConstruct
public void listar() {
    try {//  w w  w  . j ava2s.  c  om
        AgendamentoDAO agendamentoDAO = new AgendamentoDAO();
        agendamentos = agendamentoDAO.listar();
    } catch (RuntimeException erro) {
        Messages.addFlashGlobalError("Ocorreu um erro ao tentar listar o agendamento");
        erro.printStackTrace();
    }
}