Matcher m = thePattern.matcher(ex.getStackTraceString().split('\n', 3)[1]);
if (m.find()) {
String[] groups = new List<String>{
m.group(1),
m.group(2),
m.group(3),
m.group(4),
m.group(5)
};
if (String.isBlank(groups[2])) {
className = groups[0];
methodName = groups[1];
} else {
className = groups[0] + '.' + groups[1];
methodName = groups[2];
}
line = groups[3];
column = groups[4];
}
location = '{className}.{methodName}:{line},{column}'
.replace('{className}', className)
.replace('{methodName}', methodName)