The Mute Design Pattern

Have you been writing a lot of code following the Mute-Design-Pattern™ lately? E.g.

try {
catch (Exception ignore) {
    // Will never happen hehe

There’s an easier way with Java 8!

Just add this very useful tool to your Utilities or Helper class:

public class Helper {

    // 18395 lines of other code here

    interface CheckedRunnable {
        void run() throws Throwable;

    public static void mute(CheckedRunnable r) {
        try {
        catch (Throwable ignore) {
            // OK, better stay safe

    // 37831 lines of other code here

Now you can wrap all your logic in this nice little wrapper:

mute(() -> {


Even better, in some cases, you can use method references

try (Connection con = ...;
     PreparedStatement stmt = ...) {


2 thoughts on “The Mute Design Pattern

  1. We want to have it supported by JOOQ!

    C’mon: signal somethow that this is a joke! Some juniors may take you serious and may implement it. Want to let the hell loose?

Leave a Reply

Fill in your details below or click an icon to log in: Logo

You are commenting using your account. Log Out /  Change )

Google photo

You are commenting using your Google account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s

This site uses Akismet to reduce spam. Learn how your comment data is processed.