Throwing Exceptions – slow and ugly

This post is about a historical experience in conjunction with recently applied performance optimization techniques. Years ago I was swearing at a particular application where I had to discover the undocumented behaviour buried under a truly clever engineering “technique”.

It was a typical monolithic Java EE application responsible for invoicing. The exact code is best to keep forgotten, but I recall that the developer had found a truly clever way to control the flow of a business process.

Part of the flow was a usual endless if-then-else mess, but what made things more “exciting” was that some random elements of those checks were buried into custom java.lang.RuntimeException handling mechanics. So you might have code similar to the following:

if (invoice.overdue()) {  if (invoice.getCustomer().isKeyCustomer())    throw new InvoiceOverdueException(InvoiceOverdueException.KEY_CUSTOMER);  else    doSomething();}else {  if (invoice.getDueAmount() > BIG_AMOUNT)    if (invoice.getCustomer().isKeyCustomer())      //be silent    else      throw new InvoiceExceededException(invoice.getDueAmount());}

Source : http://www.javacodegeeks.com/2013/08/throwing-exceptions-slow-and-ugly.html

Back to Top