A little while back, we got to see how fun recursive sorting algorithms cam be. But that's not the only place where we can have funn + funn-1. How about ... exception handling in java!

public String waitForCreditCardProcessing(String cardNumber,int expDateMonth,int expDateYear)
  try {
    while (!getCCProcResult()) {
    return "Success!";
  } catch (Throwable except) {
    return waitForCreditCardProcessing(cardNumber,expDateMonth,expDateYear);

Adam Explains ...

getCCProcResult is another method that polls for a file that is dropped into a directory to indicate the credit card processing result. Yes, cardNumber, expDateMonth, etc. are instance variables and do not need to be passed as arguments and serve no purpose here.

Yes, it recurses when there is an exception. If something causes it to always throw an exception, it recurses until it blows the stack.

Oh... and one more thing... the calling code is:

if (!waitForCreditCardProcessing(cardNumber,expDateMonth,expDateYear).equalsIgnoreCase("Success!")) ...

Note that "Success!" just meant that the file containing the response now exists and did not indicate the result. There was other code that checked this file and reported whether the card was declined or not.

As an added bonus, it prints the card number it is waiting for settlement on to stdout. This means that the Linux server running this code would spew customer credit card numbers to it's console TTY. Anyone in the colocation facility that turned on the monitor could have gone to Vegas.

Speaking of added bonus, for the "side bar" post, we have Amazon's fast shipping secret.

[Advertisement] BuildMaster allows you to create a self-service release management platform that allows different teams to manage their applications. Explore how!