Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- public class Main {
- @Value
- @EqualsAndHashCode(callSuper = true)
- private static class Left extends Throwable {
- private final String left;
- }
- @Value
- @EqualsAndHashCode(callSuper = true)
- private static class Right extends Throwable {
- private final int right;
- }
- private static Throwable function(int x) {
- if (x > 10) {
- return new Left("asdf");
- }
- return new Right(15);
- }
- public static void main(String[] args) {
- var result = function(7);
- try {
- throw result;
- } catch (Left l) {
- System.out.println(l.getLeft());
- } catch (Right r) {
- System.out.println(r.getRight());
- } catch (Throwable throwable) {
- throwable.printStackTrace();
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement