Example usage for java.lang Throwable Throwable

List of usage examples for java.lang Throwable Throwable

Introduction

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

Prototype

public Throwable() 

Source Link

Document

Constructs a new throwable with null as its detail message.

Usage

From source file:es.bsc.servicess.ide.Logger.java

/**
 * Write INFO type logs/*from w w  w .jav  a2 s  .  co  m*/
 * @param message Message
 */
public void info(String message) {
    if (level >= INFO_LEVEL) {
        StackTraceElement invoker = new Throwable().fillInStackTrace().getStackTrace()[1];
        log.log(new Status(Status.OK, Activator.PLUGIN_ID, printInvocationInfo(invoker) + " " + message));
    }
}

From source file:com.netscape.cmscore.util.Debug.java

/**
 * Output a debug message at the output stream sepcified in the init()
 * method. This method is very lightweight if debugging is turned off, since
 * it will return immediately. However, the caller should be aware that
 * if the argument to Debug.trace() is an object whose toString() is
 * expensive, that this toString() will still be called in any case.
 * In such a case, it is wise to wrap the Debug.trace like this:
 *
 * <pre>/*from  ww  w . ja  v a2 s.  c  o  m*/
 * if (Debug.on()) {
 *     Debug.trace(&quot;obj is: &quot; + obj);
 * }
 * </pre>
 *
 * @param level the message level. If this is >= than the currently set
 *            level (set with setLevel() ), the message is printed
 * @param t the message to print
 * @param ignoreStack when walking the stack to determine the
 *            location of the method that called the trace() method,
 *            ignore any classes with this string in. Can be null
 * @param printCaller if true, (and if static mShowCaller is true)
 *            dump caller information in this format:
 *            (source-file:line) methodname():
 */
public static void trace(int level, String t, String ignoreStack, boolean printCaller) {
    String callerinfo = "";
    if (!TRACE_ON)
        return;
    if (level >= mDebugLevel) {
        if (mShowCaller && printCaller) {
            String method = "";
            String fileAndLine = "";

            try {
                Throwable tr = new Throwable();
                StackTraceElement ste[] = tr.getStackTrace();
                int i = 0;
                while ((i < ste.length) && (ste[i].getMethodName().toLowerCase().indexOf("debug") > -1)
                        || (ste[i].getMethodName().toLowerCase().indexOf("hashkey") > -1)
                        || (ste[i].getClassName().toLowerCase().indexOf("propconfigstore") > -1)
                        || (ste[i].getClassName().toLowerCase().indexOf("argblock") > -1)
                        || (ste[i].getClassName().toLowerCase().indexOf("debug") > -1)
                        || (ste[i].getMethodName().toLowerCase().indexOf("trace") > -1))
                    i++;

                if (i < ste.length) {
                    fileAndLine = ste[i].getFileName() + ":" + ste[i].getLineNumber();
                    method = ste[i].getMethodName() + "()";
                }

                callerinfo = fileAndLine + ":" + method + " ";
            } catch (Exception f) {
            }
        }

        outputTraceMessage(callerinfo + t);
    }
}

From source file:jetbrains.exodus.entitystore.Explainer.java

public Object genOrigin() {
    if (Explainer.isExplainForcedForThread()) {
        return Thread.currentThread();
    } else if (explainOn) {
        return new Throwable();
    }/* w w w  .j  av  a 2 s  .c o  m*/
    return null;
}

From source file:games.stendhal.server.entity.npc.action.DropInfostringItemAction.java

@Override
public void fire(final Player player, final Sentence sentence, final EventRaiser npc) {
    final List<Item> items = player.getAllEquipped(itemName);
    boolean res = false;
    for (final Item item : items) {
        if (infostring.equalsIgnoreCase(item.getInfoString())) {
            res = player.drop(item.getName(), amount);
            break;
        }/*  w  w  w  . j a  v a 2  s  . co  m*/
    }

    if (!res) {
        logger.error("Cannot drop " + itemName, new Throwable());
    }
    player.notifyWorldAboutChanges();
}

From source file:games.stendhal.server.entity.npc.action.EquipRandomAmountOfItemAction.java

@Override
public void fire(final Player player, final Sentence sentence, final EventRaiser npc) {
    if ((increment <= 0) || ((increment > max) && ((increment > min)))) {
        logger.error("Increment value '" + increment + "' is invalid when max is '" + max + "'.",
                new Throwable());
    } else if ((min <= 0) || (max <= 0)) {
        logger.error("Invalid min/max values '" + min + "', '" + max + "'.", new Throwable());
    } else {//from  w w w. j  a  v  a2  s.c o m
        final String itemName = item;
        int attempt = Rand.randUniform(min, max);
        if (attempt % increment != 0) {
            // if the number isn't a multiple of increment, round it to nearest
            attempt = (attempt / increment) * increment;
            if (attempt == 0) {
                attempt = Math.min(min, max);
            }
        }
        final Integer amount = attempt;
        new EquipItemAction(itemName, amount, false).fire(player, null, null);
    }
}

From source file:com.comcast.video.dawg.cats.power.PowerClientTest.java

@Test
public void testPowerException() {
    String msg = "msg";
    PowerException exp = new PowerException(msg);
    Assert.assertEquals(exp.getMessage(), msg);
    exp = new PowerException(new Throwable());
    Assert.assertNotEquals(exp.getMessage(), msg);
}

From source file:org.eclipse.vjet.dsf.common.trace.DefaultTracer.java

public void exitMethod(final Object caller) {

    if (!m_traceEnabled) {
        return;//from   w w w  .j av a 2 s .  c  o m
    }

    if (caller == null) {
        return;
    }

    final Throwable t = new Throwable();
    t.fillInStackTrace();

    final String clsName = getClassName(caller);
    final String methodName = getMethodName(caller, t);

    dispatch(new WriterInvoker() {
        public void process(ITraceWriter w) {
            w.handleExitMethod(m_traceDepth, clsName, methodName);
        }
    });

    pop(clsName + DOT + methodName);
}

From source file:fr.aliasource.webmail.proxy.Controller.java

/**
 * Verifies login & creates imap caching proxy if valid.
 * //www .  j  a v a2s  .co  m
 * @param req
 * @param responder
 */
private void validateLoginRequest(HttpServletRequest req, IResponder responder) {
    if ("/login.do".equals(req.getRequestURI())) {
        loginHandling(req, responder, false);
    } else if ("/firstIndexing.do".equals(req.getRequestURI())) {
        IProxy p = loginHandling(req, responder, true);
        if (p != null) {
            try {
                Thread.sleep(20 * 1000);
            } catch (InterruptedException e) {
            }
            logout(p);
            responder.sendString("First indexing complete.");
        } else {
            logger.error("null proxy from loginHandling", new Throwable());
        }
        logger.info("leaving first indexing");
    } else {
        responder.denyAccess("not a login request");
    }
}

From source file:org.artifactory.request.ArtifactoryResponseBase.java

@Override
public void sendSuccess() {
    if (isSuccessful() || HttpUtils.isRedirectionResponseCode(status)) {
        flush();/* w  ww . j  a v  a 2  s.  com*/
    } else {
        log.error("Could not send success. Exiting status: {}.", status);
        if (log.isDebugEnabled()) {
            log.debug("Could not send success.", new Throwable());
        }
    }
}

From source file:io.kahu.hawaii.rest.DefaultResponseManagerTest.java

@Test
public void testToResponseWithRuntimeException() throws Exception {
    ResponseEntity<?> response = responseManager.toResponse(new Throwable());
    assertThat(response.getStatusCode(), is(equalTo(HttpStatus.OK)));

    response = responseManager.toResponse(new AssertionError());
    assertThat(response.getStatusCode(), is(equalTo(HttpStatus.OK)));

    response = responseManager.toResponse(new NullPointerException());
    assertThat(response.getStatusCode(), is(equalTo(HttpStatus.OK)));

    verify(logManager, times(3))/*from  ww w . j a v  a 2 s. co  m*/
            .logIncomingCallEnd(Mockito.argThat(new TestInstanceOfMatcher<>(HawaiiException.class)));
}