Skip to content

Let Unchecked.throwChecked return RuntimeException to improve control flow #324

Description

@leaumar

AS-IS

class Unchecked {
	public static void throwChecked(Throwable t) {
		SeqUtils.sneakyThrow(t);
	}
}
public Object foo() {
	if (condition) {
		return bar();
	} else {
		Unchecked.throwChecked(new Exception());
		return null;
	}
}

TO-BE

class Unchecked {
	public static <T> T throwChecked(Throwable t) {
		SeqUtils.sneakyThrow(t);
		return null;
	}
}
public Object foo() {
	if (condition) {
		return bar();
	} else {
		return Unchecked.throwChecked(new Exception());
	}
}

Versions:

  • jOOλ: 0.9.12
  • Java: 1.8.0.91

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions