From ac53949c63cb34fa3312b6545dee3e1fd723c48d Mon Sep 17 00:00:00 2001 From: mickalma Date: Fri, 27 Jan 2023 18:29:27 +0100 Subject: [PATCH] raise an exception when Error occurs, like TypeError --- src/Controller/ErnParserController.php | 12 +++++++++--- 1 file changed, 9 insertions(+), 3 deletions(-) diff --git a/src/Controller/ErnParserController.php b/src/Controller/ErnParserController.php index d186fbc..e716498 100644 --- a/src/Controller/ErnParserController.php +++ b/src/Controller/ErnParserController.php @@ -772,10 +772,16 @@ public function parse(string $file_path) { // Parse XML now while ($data = fread($fp, 4096)) { - if (!xml_parse($this->xml_parser, $data, feof($fp))) { + try { + if (!xml_parse($this->xml_parser, $data, feof($fp))) { + throw new XmlParseException(sprintf("XML Error: %s at line %d\n", + xml_error_string(xml_get_error_code($this->xml_parser)), + xml_get_current_line_number($this->xml_parser))); + } + } catch (\Error $er) { throw new XmlParseException(sprintf("XML Error: %s at line %d\n", - xml_error_string(xml_get_error_code($this->xml_parser)), - xml_get_current_line_number($this->xml_parser))); + $er->getMessage(), + $er->getLine())); } }