There are things you can do in Java you rarely see, generally because there is no use for it. However, there are some unusual things in Java that could be surprisingly useful. Chronicle Software uses a number of different usual patterns in it’s low-level libraries most developers wouldn’t generally come across. One of them is a class that extends Throwable but isn’t an Error or an Exception. StackTrace Extends Throwable package net.openhft.chronicle.core; /** * Throwable created purely for the purposes of reporting a stack trace. * This is not an Error or an Exception and is not expected to be thrown or caught. */ public class StackTrace extends Throwable { public StackTrace() { this ( "stack trace" ); } public StackTrace(String message) { this (message, null ); } public StackTrace(String message, Throwable cause) { super (message + " on " + Thread. currentThread ().getName(), cause); } public static StackTrace forThread(Thread t) {
Comments
Post a Comment