Check whether a throw at `offset` in the function body is caught by one of the `catches`, given the exception type.
(
catches: &[CatchInfo],
offset: usize,
exc_type: &PhpType,
use_map: &HashMap<String, String>,
file_namespace: &Option<String>,
class_loader: OptClassLo
| 1057 | /// Check whether a throw at `offset` in the function body is caught |
| 1058 | /// by one of the `catches`, given the exception type. |
| 1059 | fn is_caught_by( |
| 1060 | catches: &[CatchInfo], |
| 1061 | offset: usize, |
| 1062 | exc_type: &PhpType, |
| 1063 | use_map: &HashMap<String, String>, |
| 1064 | file_namespace: &Option<String>, |
| 1065 | class_loader: OptClassLoader<'_>, |
| 1066 | ) -> bool { |
| 1067 | let exc_name = exc_type.base_name().unwrap_or(""); |
| 1068 | // Resolve exception type to FQN via class loader if available. |
| 1069 | let exc_fqn = if let Some(loader) = class_loader { |
| 1070 | loader(exc_name) |
| 1071 | .map(|cls| cls.fqn().to_string()) |
| 1072 | .unwrap_or_else(|| exc_name.to_string()) |
| 1073 | } else { |
| 1074 | exc_name.to_string() |
| 1075 | }; |
| 1076 | catches.iter().any(|c| { |
| 1077 | offset > c.try_start |
| 1078 | && offset < c.try_end |
| 1079 | && c.type_names.iter().any(|ct| { |
| 1080 | let ct_name = ct.base_name().unwrap_or(""); |
| 1081 | // Resolve the catch type to FQN |
| 1082 | let resolved_ct = crate::util::resolve_to_fqn(ct_name, use_map, file_namespace); |
| 1083 | // Also try through the class loader for root-namespace classes. |
| 1084 | let resolved_ct = if let Some(loader) = class_loader { |
| 1085 | loader(&resolved_ct) |
| 1086 | .or_else(|| loader(ct_name)) |
| 1087 | .map(|cls| cls.fqn().to_string()) |
| 1088 | .unwrap_or(resolved_ct) |
| 1089 | } else { |
| 1090 | resolved_ct |
| 1091 | }; |
| 1092 | // Check for Throwable/Exception (catches everything). |
| 1093 | let resolved_lower = resolved_ct.to_ascii_lowercase(); |
| 1094 | if resolved_lower == "throwable" || resolved_lower == "exception" { |
| 1095 | return true; |
| 1096 | } |
| 1097 | // Exact FQN comparison (case-insensitive) |
| 1098 | resolved_ct.eq_ignore_ascii_case(&exc_fqn) |
| 1099 | }) |
| 1100 | }) |
| 1101 | } |
| 1102 | |
| 1103 | /// Normalize a ThrowInfo's type_name into a PhpType::Named, |
| 1104 | /// resolving short names to FQN when use_map/namespace are available. |
no test coverage detected