Advertisement
Guest User

Untitled

a guest
Nov 21st, 2019
106
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 0.74 KB | None | 0 0
  1. public class Main {
  2.  
  3.   @Value
  4.   @EqualsAndHashCode(callSuper = true)
  5.   private static class Left extends Throwable {
  6.     private final String left;
  7.   }
  8.  
  9.   @Value
  10.   @EqualsAndHashCode(callSuper = true)
  11.   private static class Right extends Throwable {
  12.     private final int right;
  13.   }
  14.  
  15.   private static Throwable function(int x) {
  16.     if (x > 10) {
  17.       return new Left("asdf");
  18.     }
  19.     return new Right(15);
  20.   }
  21.   public static void main(String[] args) {
  22.     var result = function(7);
  23.     try {
  24.       throw result;
  25.     } catch (Left l) {
  26.       System.out.println(l.getLeft());
  27.     } catch (Right r) {
  28.       System.out.println(r.getRight());
  29.     } catch (Throwable throwable) {
  30.       throwable.printStackTrace();
  31.     }
  32.   }
  33. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement