Fix bug and failed test in assertThrows