Be defensive when calling toString() on object in MatchError.getMessage #7912
If Throwable.getMessage throws an exception, no matter whose fault it is, this will make debugging an application that throws such an exception very difficult, because the original exception will be lost when a logger tries to log the exception message. Scalas MatchError.getMessage method will throw an exception if the object that failed to match throws an exception from its toString method. That object of course shouldn't throw an exception from its toString method, but if that object is from a third party library and you just want to debug your application, knowing who to blame is little consolation.
MatchError.getMessage should therefore be defensive when invoking toString on the object, catching any exceptions caught, and if such an exception was caught, displaying a message like this instead:
It could probably also add information about exception caught, eg saying "Additionally, an exception was thrown when the toString() method was invoked: ...", but this is not strictly necessary.
The text was updated successfully, but these errors were encountered: