improved mysql exception sorter