Created
January 2, 2014 21:09
-
-
Save evacchi/8226980 to your computer and use it in GitHub Desktop.
Blue.Pill -- RuntimeException with NoStackTrace for Java (inspired by Scala's NoStackTrace trait)
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/** | |
* You take the Blue.Pill. You wake up in your bed and believe whatever you want to. | |
* Usage: <code>throw Blue.Pill</code>, then, somewhere else: | |
* try { ... } catch (Blue Pill) { /* possibly do something */ } | |
* | |
* @author edoardovacchi | |
*/ | |
public abstract class Blue extends RuntimeException { | |
public static Blue.Pill Pill = new Blue.Pill(); | |
/** | |
* inspired by Scala's NoStackTrace trait | |
* | |
* @return this instance, with no stack trace | |
*/ | |
@Override | |
public Throwable fillInStackTrace() { | |
return this; | |
} | |
private static class Pill extends Blue {} | |
} |
Author
evacchi
commented
Mar 10, 2014
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment