Last active
August 18, 2023 15:32
-
-
Save Andrewp2/9d97bd213b061166d6df565ce26dc838 to your computer and use it in GitHub Desktop.
java
This file contains hidden or 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
| import static java.lang.Thread.sleep; | |
| public class Main { | |
| public static void main(String[] args) { | |
| try { | |
| Validation validation = validate(); | |
| try { | |
| Value value = update_db(validation); | |
| send_email(value); | |
| } catch (DBError db) { | |
| try { | |
| sleep(5); | |
| Value value = update_db(validation); | |
| send_email(value); | |
| } catch(InterruptedException ie) { | |
| // do nothing, stupid java-ism | |
| } catch(DBError db2) { | |
| try { | |
| Value value = update_db_remote(validation); | |
| send_email(value); | |
| } catch (DBError db3) { | |
| notify_user(db3); | |
| } catch (EmailFailedError e) { | |
| requeue_email(e); | |
| } | |
| } catch (EmailFailedError e) { | |
| requeue_email(e); | |
| } | |
| } catch (EmailFailedError e) { | |
| requeue_email(e); | |
| } | |
| } catch(ValidationError v) { | |
| notify_user(v); | |
| } | |
| } | |
| public static void requeue_email(EmailFailedError e) { | |
| // do something to requeue email | |
| } | |
| private static Validation validate() throws ValidationError { | |
| return new Validation("credentials"); | |
| } | |
| private static Value update_db(Validation validation) throws DBError { | |
| return new Value(4); | |
| } | |
| private static Value update_db_remote(Validation validation) throws DBError { | |
| return new Value(5); | |
| } | |
| private static void send_email(Value value) throws EmailFailedError { | |
| System.out.println("Sending email"); | |
| } | |
| private static void notify_user(ValidationError ve) { | |
| System.out.println("oh no an error"); | |
| } | |
| private static void notify_user(DBError ve) { | |
| System.out.println("oh no an error 2"); | |
| } | |
| private static class ValidationError extends Throwable { | |
| } | |
| private static class DBError extends Throwable { | |
| } | |
| private static class EmailFailedError extends Throwable { | |
| } | |
| private static class Validation { | |
| String str; | |
| public Validation(String str) { | |
| this.str = str; | |
| } | |
| } | |
| private static class Value { | |
| int my_val; | |
| public Value(int my_val) { | |
| this.my_val = my_val; | |
| } | |
| } | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment