Use logout as the last step in try block and after the getLastError in the catch block by doing this you don’t need a finally sequence.
Do you need finally block at any cost?