Commit b394bfc5af6 for php.net

commit b394bfc5af6c003d02d323efc5d3c4cd96ef3900
Author: NickSdot <32384907+NickSdot@users.noreply.github.com>
Date:   Sat Aug 22 20:26:23 2026 +0700

    ext/dom: applied fixers to improve test robustness (#23130)

diff --git a/ext/dom/tests/DOM4_ChildNode_wrong_document.phpt b/ext/dom/tests/DOM4_ChildNode_wrong_document.phpt
index cf51c3581a3..5942a4cf75f 100644
--- a/ext/dom/tests/DOM4_ChildNode_wrong_document.phpt
+++ b/ext/dom/tests/DOM4_ChildNode_wrong_document.phpt
@@ -18,8 +18,8 @@ function test($method) {
     try {
         $element->$method($dom2->documentElement->firstChild);
         echo "FAIL";
-    } catch (DOMException $e) {
-        echo $e->getMessage() . "\n";
+    } catch (Throwable $e) {
+        echo $e::class, ': ', $e->getMessage(), "\n";
     }
 }

@@ -29,6 +29,6 @@ function test($method) {

 ?>
 --EXPECT--
-Wrong Document Error
-Wrong Document Error
-Wrong Document Error
+DOMException: Wrong Document Error
+DOMException: Wrong Document Error
+DOMException: Wrong Document Error
diff --git a/ext/dom/tests/DOM4_DOMNode_removeDanglingElement.phpt b/ext/dom/tests/DOM4_DOMNode_removeDanglingElement.phpt
index 3890ef08d5b..b1db57e4f31 100644
--- a/ext/dom/tests/DOM4_DOMNode_removeDanglingElement.phpt
+++ b/ext/dom/tests/DOM4_DOMNode_removeDanglingElement.phpt
@@ -11,9 +11,9 @@

 try {
     $element->remove();
-} catch (DOMException $e) {
-    echo $e->getMessage();
+} catch (Throwable $e) {
+    echo $e::class, ': ', $e->getMessage(), "\n";
 }
 ?>
 --EXPECT--
-Not Found Error
+DOMException: Not Found Error
diff --git a/ext/dom/tests/DOM4_ParentNode_append_invalidtypes.phpt b/ext/dom/tests/DOM4_ParentNode_append_invalidtypes.phpt
index 9a823e370a6..2583bbe3178 100644
--- a/ext/dom/tests/DOM4_ParentNode_append_invalidtypes.phpt
+++ b/ext/dom/tests/DOM4_ParentNode_append_invalidtypes.phpt
@@ -11,9 +11,9 @@

 try {
     $dom->documentElement->append(array());
-} catch(TypeError $e) {
-    echo "OK! {$e->getMessage()}";
+} catch(Throwable $e) {
+    echo $e::class, ': ', $e->getMessage(), "\n";
 }
 ?>
 --EXPECT--
-OK! DOMElement::append(): Argument #1 must be of type DOMNode|string, array given
+TypeError: DOMElement::append(): Argument #1 must be of type DOMNode|string, array given
diff --git a/ext/dom/tests/DOM4_ParentNode_append_with_attributes.phpt b/ext/dom/tests/DOM4_ParentNode_append_with_attributes.phpt
index 701dc1d0944..75c6bc44d90 100644
--- a/ext/dom/tests/DOM4_ParentNode_append_with_attributes.phpt
+++ b/ext/dom/tests/DOM4_ParentNode_append_with_attributes.phpt
@@ -18,13 +18,13 @@

 try {
     $element->append($replacement, $addition);
-} catch (DOMException $e) {
-    echo $e->getMessage() . "\n";
+} catch (Throwable $e) {
+    echo $e::class, ': ', $e->getMessage(), "\n";
 }

 echo $dom->saveXML();
 ?>
 --EXPECT--
-Hierarchy Request Error
+DOMException: Hierarchy Request Error
 <?xml version="1.0"?>
 <test attr-one="21"/>
diff --git a/ext/dom/tests/DOM4_ParentNode_append_wrong_document.phpt b/ext/dom/tests/DOM4_ParentNode_append_wrong_document.phpt
index 9df1603cab0..ec30546b8b5 100644
--- a/ext/dom/tests/DOM4_ParentNode_append_wrong_document.phpt
+++ b/ext/dom/tests/DOM4_ParentNode_append_wrong_document.phpt
@@ -18,8 +18,8 @@ function test($method) {
     try {
         $element->$method($dom2->documentElement->firstChild);
         echo "FAIL";
-    } catch (DOMException $e) {
-        echo $e->getMessage() . "\n";
+    } catch (Throwable $e) {
+        echo $e::class, ': ', $e->getMessage(), "\n";
     }
 }

@@ -27,5 +27,5 @@ function test($method) {
 test("prepend");
 ?>
 --EXPECT--
-Wrong Document Error
-Wrong Document Error
+DOMException: Wrong Document Error
+DOMException: Wrong Document Error
diff --git a/ext/dom/tests/DOMAttr_construct_error_001.phpt b/ext/dom/tests/DOMAttr_construct_error_001.phpt
index 0839587caf4..1f4f73806d0 100644
--- a/ext/dom/tests/DOMAttr_construct_error_001.phpt
+++ b/ext/dom/tests/DOMAttr_construct_error_001.phpt
@@ -9,9 +9,9 @@
 <?php
 try {
     $attr = new DOMAttr();
-} catch (TypeError $e) {
-    echo $e->getMessage(), "\n";
+} catch (Throwable $e) {
+    echo $e::class, ': ', $e->getMessage(), "\n";
 }
 ?>
 --EXPECT--
-DOMAttr::__construct() expects at least 1 argument, 0 given
+ArgumentCountError: DOMAttr::__construct() expects at least 1 argument, 0 given
diff --git a/ext/dom/tests/DOMCDATASection_construct_error_001.phpt b/ext/dom/tests/DOMCDATASection_construct_error_001.phpt
index 50aacf05b9b..9a3ba644889 100644
--- a/ext/dom/tests/DOMCDATASection_construct_error_001.phpt
+++ b/ext/dom/tests/DOMCDATASection_construct_error_001.phpt
@@ -9,9 +9,9 @@
 <?php
     try {
         $section = new DOMCDataSection();
-    } catch (TypeError $e) {
-        echo $e->getMessage();
+    } catch (Throwable $e) {
+        echo $e::class, ': ', $e->getMessage(), "\n";
     }
 ?>
 --EXPECT--
-DOMCdataSection::__construct() expects exactly 1 argument, 0 given
+ArgumentCountError: DOMCdataSection::__construct() expects exactly 1 argument, 0 given
diff --git a/ext/dom/tests/DOMCharacterData_data_error_002.phpt b/ext/dom/tests/DOMCharacterData_data_error_002.phpt
index 71ef411a5cf..f6fce4cc9c9 100644
--- a/ext/dom/tests/DOMCharacterData_data_error_002.phpt
+++ b/ext/dom/tests/DOMCharacterData_data_error_002.phpt
@@ -10,9 +10,9 @@
 $character_data = new DOMCharacterData();
 try {
     print $character_data->data;
-} catch (DOMException $exception) {
-    echo $exception->getMessage() . "\n";
+} catch (Throwable $exception) {
+    echo $exception::class, ': ', $exception->getMessage(), "\n";
 }
 ?>
 --EXPECT--
-Invalid State Error
+DOMException: Invalid State Error
diff --git a/ext/dom/tests/DOMCharacterData_deleteData_error_002.phpt b/ext/dom/tests/DOMCharacterData_deleteData_error_002.phpt
index 071ac52abf2..0da7f7b5e41 100644
--- a/ext/dom/tests/DOMCharacterData_deleteData_error_002.phpt
+++ b/ext/dom/tests/DOMCharacterData_deleteData_error_002.phpt
@@ -15,9 +15,9 @@
 $root->appendChild($cdata);
 try {
     $cdata->deleteData(5, 1);
-} catch (DOMException $e) {
-    echo $e->getMessage();
+} catch (Throwable $e) {
+    echo $e::class, ': ', $e->getMessage(), "\n";
 }
 ?>
 --EXPECT--
-Index Size Error
+DOMException: Index Size Error
diff --git a/ext/dom/tests/DOMCharacterData_length_error_001.phpt b/ext/dom/tests/DOMCharacterData_length_error_001.phpt
index 8f0c66a12e7..7c446c1fc66 100644
--- a/ext/dom/tests/DOMCharacterData_length_error_001.phpt
+++ b/ext/dom/tests/DOMCharacterData_length_error_001.phpt
@@ -10,9 +10,9 @@
 $character_data = new DOMCharacterData();
 try {
     print $character_data->length;
-} catch (DOMException $exception) {
-    echo $exception->getMessage() . "\n";
+} catch (Throwable $exception) {
+    echo $exception::class, ': ', $exception->getMessage(), "\n";
 }
 ?>
 --EXPECT--
-Invalid State Error
+DOMException: Invalid State Error
diff --git a/ext/dom/tests/DOMComment_construct_error_001.phpt b/ext/dom/tests/DOMComment_construct_error_001.phpt
index 573a493827e..eddb88e2be7 100644
--- a/ext/dom/tests/DOMComment_construct_error_001.phpt
+++ b/ext/dom/tests/DOMComment_construct_error_001.phpt
@@ -9,9 +9,9 @@
 <?php
 try {
     $comment = new DOMComment("comment1", "comment2");
-} catch (TypeError $e) {
-    echo $e->getMessage(), "\n";
+} catch (Throwable $e) {
+    echo $e::class, ': ', $e->getMessage(), "\n";
 }
 ?>
 --EXPECT--
-DOMComment::__construct() expects at most 1 argument, 2 given
+ArgumentCountError: DOMComment::__construct() expects at most 1 argument, 2 given
diff --git a/ext/dom/tests/DOMDocumentFragment_appendXML_error_002.phpt b/ext/dom/tests/DOMDocumentFragment_appendXML_error_002.phpt
index 85ff6b7667d..ec866383607 100644
--- a/ext/dom/tests/DOMDocumentFragment_appendXML_error_002.phpt
+++ b/ext/dom/tests/DOMDocumentFragment_appendXML_error_002.phpt
@@ -10,9 +10,9 @@
 $fragment = new DOMDocumentFragment();
 try {
     $fragment->appendXML('<bait>crankbait</bait>');
-} catch (DOMException $e) {
-    echo $e->getMessage();
+} catch (Throwable $e) {
+    echo $e::class, ': ', $e->getMessage(), "\n";
 }
 ?>
 --EXPECT--
-No Modification Allowed Error
+DOMException: No Modification Allowed Error
diff --git a/ext/dom/tests/DOMDocumentFragment_construct_error_001.phpt b/ext/dom/tests/DOMDocumentFragment_construct_error_001.phpt
index b05e1efc5f0..d025a7951cb 100644
--- a/ext/dom/tests/DOMDocumentFragment_construct_error_001.phpt
+++ b/ext/dom/tests/DOMDocumentFragment_construct_error_001.phpt
@@ -9,9 +9,9 @@
 <?php
 try {
     $fragment = new DOMDocumentFragment("root");
-} catch (TypeError $e) {
-    echo $e->getMessage(), "\n";
+} catch (Throwable $e) {
+    echo $e::class, ': ', $e->getMessage(), "\n";
 }
 ?>
 --EXPECT--
-DOMDocumentFragment::__construct() expects exactly 0 arguments, 1 given
+ArgumentCountError: DOMDocumentFragment::__construct() expects exactly 0 arguments, 1 given
diff --git a/ext/dom/tests/DOMDocumentType_entities_error_001.phpt b/ext/dom/tests/DOMDocumentType_entities_error_001.phpt
index 3385a2f4e09..5b1eada0865 100644
--- a/ext/dom/tests/DOMDocumentType_entities_error_001.phpt
+++ b/ext/dom/tests/DOMDocumentType_entities_error_001.phpt
@@ -10,9 +10,9 @@
 $doctype = new DOMDocumentType();
 try {
     $doctype->entities;
-} catch (DOMException $exception) {
-    echo $exception->getMessage() . "\n";
+} catch (Throwable $exception) {
+    echo $exception::class, ': ', $exception->getMessage(), "\n";
 }
 ?>
 --EXPECT--
-Invalid State Error
+DOMException: Invalid State Error
diff --git a/ext/dom/tests/DOMDocumentType_internalSubset_error_001.phpt b/ext/dom/tests/DOMDocumentType_internalSubset_error_001.phpt
index efd00bc3bb1..0de4fb21e9a 100644
--- a/ext/dom/tests/DOMDocumentType_internalSubset_error_001.phpt
+++ b/ext/dom/tests/DOMDocumentType_internalSubset_error_001.phpt
@@ -10,9 +10,9 @@
 $doctype = new DOMDocumentType();
 try {
     $doctype->internalSubset;
-} catch (DOMException $exception) {
-    echo $exception->getMessage() . "\n";
+} catch (Throwable $exception) {
+    echo $exception::class, ': ', $exception->getMessage(), "\n";
 }
 ?>
 --EXPECT--
-Invalid State Error
+DOMException: Invalid State Error
diff --git a/ext/dom/tests/DOMDocumentType_name_error_001.phpt b/ext/dom/tests/DOMDocumentType_name_error_001.phpt
index 7714613a0ef..ab64a425a5f 100644
--- a/ext/dom/tests/DOMDocumentType_name_error_001.phpt
+++ b/ext/dom/tests/DOMDocumentType_name_error_001.phpt
@@ -10,9 +10,9 @@
 $doctype = new DOMDocumentType();
 try {
     $doctype->name;
-} catch (DOMException $exception) {
-    echo $exception->getMessage() . "\n";
+} catch (Throwable $exception) {
+    echo $exception::class, ': ', $exception->getMessage(), "\n";
 }
 ?>
 --EXPECT--
-Invalid State Error
+DOMException: Invalid State Error
diff --git a/ext/dom/tests/DOMDocumentType_notations_error_001.phpt b/ext/dom/tests/DOMDocumentType_notations_error_001.phpt
index 9fa1c7510a6..080fb85522f 100644
--- a/ext/dom/tests/DOMDocumentType_notations_error_001.phpt
+++ b/ext/dom/tests/DOMDocumentType_notations_error_001.phpt
@@ -10,9 +10,9 @@
 $doctype = new DOMDocumentType();
 try {
     $notations = $doctype->notations;
-} catch (DOMException $exception) {
-    echo $exception->getMessage() . "\n";
+} catch (Throwable $exception) {
+    echo $exception::class, ': ', $exception->getMessage(), "\n";
 }
 ?>
 --EXPECT--
-Invalid State Error
+DOMException: Invalid State Error
diff --git a/ext/dom/tests/DOMDocumentType_publicId_error_001.phpt b/ext/dom/tests/DOMDocumentType_publicId_error_001.phpt
index 1a7fcd3feb4..f798f4191da 100644
--- a/ext/dom/tests/DOMDocumentType_publicId_error_001.phpt
+++ b/ext/dom/tests/DOMDocumentType_publicId_error_001.phpt
@@ -10,9 +10,9 @@
 $doctype = new DOMDocumentType();
 try {
     $publicId = $doctype->publicId;
-} catch (DOMException $exception) {
-    echo $exception->getMessage() . "\n";
+} catch (Throwable $exception) {
+    echo $exception::class, ': ', $exception->getMessage(), "\n";
 }
 ?>
 --EXPECT--
-Invalid State Error
+DOMException: Invalid State Error
diff --git a/ext/dom/tests/DOMDocumentType_systemId_error_001.phpt b/ext/dom/tests/DOMDocumentType_systemId_error_001.phpt
index 3d5f7827eaa..fa41a8098a5 100644
--- a/ext/dom/tests/DOMDocumentType_systemId_error_001.phpt
+++ b/ext/dom/tests/DOMDocumentType_systemId_error_001.phpt
@@ -10,9 +10,9 @@
 $doctype = new DOMDocumentType();
 try {
     $systemId = $doctype->systemId;
-} catch (DOMException $exception) {
-    echo $exception->getMessage() . "\n";
+} catch (Throwable $exception) {
+    echo $exception::class, ': ', $exception->getMessage(), "\n";
 }
 ?>
 --EXPECT--
-Invalid State Error
+DOMException: Invalid State Error
diff --git a/ext/dom/tests/DOMDocument_adoptNode.phpt b/ext/dom/tests/DOMDocument_adoptNode.phpt
index 2382cabd513..5ecaef0083a 100644
--- a/ext/dom/tests/DOMDocument_adoptNode.phpt
+++ b/ext/dom/tests/DOMDocument_adoptNode.phpt
@@ -20,8 +20,8 @@
 echo "-- Trying to append child from other document --\n";
 try {
     $doc2->firstChild->appendChild($b_tag_element); // Should fail because it's another document
-} catch (\DOMException $e) {
-    echo $e->getMessage(), "\n";
+} catch (\Throwable $e) {
+    echo $e::class, ': ', $e->getMessage(), "\n";
 }

 echo "-- Adopting --\n";
@@ -47,8 +47,8 @@

 try {
     $doc1->adoptNode($doc1);
-} catch (\DOMException $e) {
-    echo $e->getMessage(), "\n";
+} catch (\Throwable $e) {
+    echo $e::class, ': ', $e->getMessage(), "\n";
 }

 echo "-- Adopt a document (strict error off) --\n";
@@ -56,8 +56,8 @@
 $doc1->strictErrorChecking = false;
 try {
     $doc1->adoptNode($doc1);
-} catch (\DOMException $e) {
-    echo $e->getMessage(), "\n";
+} catch (\Throwable $e) {
+    echo $e::class, ': ', $e->getMessage(), "\n";
 }
 $doc1->strictErrorChecking = true;

@@ -117,7 +117,7 @@
 bool(true)
 bool(false)
 -- Trying to append child from other document --
-Wrong Document Error
+DOMException: Wrong Document Error
 -- Adopting --
 string(3) "hix"
 string(35) "<?xml version="1.0"?>
@@ -138,7 +138,7 @@
 <p/>
 "
 -- Adopt a document (strict error on) --
-Not Supported Error
+DOMException: Not Supported Error
 -- Adopt a document (strict error off) --

 Warning: DOMDocument::adoptNode(): Not Supported Error in %s on line %d
diff --git a/ext/dom/tests/DOMDocument_createEntityReference_error1.phpt b/ext/dom/tests/DOMDocument_createEntityReference_error1.phpt
index 381dd3d5557..736687080e5 100644
--- a/ext/dom/tests/DOMDocument_createEntityReference_error1.phpt
+++ b/ext/dom/tests/DOMDocument_createEntityReference_error1.phpt
@@ -8,11 +8,11 @@

 try {
     $objDoc->createEntityReference('!');
-} catch (DOMException $e) {
+} catch (Throwable $e) {
     var_dump($e->getCode() === DOM_INVALID_CHARACTER_ERR);
-    echo $e->getMessage();
+    echo $e::class, ': ', $e->getMessage(), "\n";
 }
 ?>
 --EXPECT--
 bool(true)
-Invalid Character Error
+DOMException: Invalid Character Error
diff --git a/ext/dom/tests/DOMDocument_encoding_basic.phpt b/ext/dom/tests/DOMDocument_encoding_basic.phpt
index 8d7f11e1cc2..30237c39512 100644
--- a/ext/dom/tests/DOMDocument_encoding_basic.phpt
+++ b/ext/dom/tests/DOMDocument_encoding_basic.phpt
@@ -24,8 +24,8 @@
 try {
     $ret = $dom->encoding = 'NYPHP DOMinatrix';
     echo "Adding invalid encoding: $ret\n";
-} catch (\ValueError $e) {
-    echo $e->getMessage() . \PHP_EOL;
+} catch (\Throwable $e) {
+    echo $e::class, ': ', $e->getMessage(), "\n";
 }

 $ret = $dom->encoding = 'ISO-8859-1';
@@ -44,7 +44,7 @@
 ?>
 --EXPECT--
 Empty Encoding Read: ''
-Invalid document encoding
+ValueError: Invalid document encoding
 Adding ISO-8859-1 encoding: ISO-8859-1
 ISO-8859-1 Encoding Read: ISO-8859-1
 Adding UTF-8 encoding: UTF-8
diff --git a/ext/dom/tests/DOMDocument_loadHTML_error2.phpt b/ext/dom/tests/DOMDocument_loadHTML_error2.phpt
index 6886240e595..6d194309b58 100644
--- a/ext/dom/tests/DOMDocument_loadHTML_error2.phpt
+++ b/ext/dom/tests/DOMDocument_loadHTML_error2.phpt
@@ -9,9 +9,9 @@
 $doc = new DOMDocument();
 try {
     $doc->loadHTML('');
-} catch (ValueError $e) {
-    echo $e->getMessage() . "\n";
+} catch (Throwable $e) {
+    echo $e::class, ': ', $e->getMessage(), "\n";
 }
 ?>
 --EXPECT--
-DOMDocument::loadHTML(): Argument #1 ($source) must not be empty
+ValueError: DOMDocument::loadHTML(): Argument #1 ($source) must not be empty
diff --git a/ext/dom/tests/DOMDocument_loadHTMLfile_error2.phpt b/ext/dom/tests/DOMDocument_loadHTMLfile_error2.phpt
index a5ef58a6565..b508c3deb5d 100644
--- a/ext/dom/tests/DOMDocument_loadHTMLfile_error2.phpt
+++ b/ext/dom/tests/DOMDocument_loadHTMLfile_error2.phpt
@@ -11,17 +11,17 @@
 $doc = new DOMDocument();
 try {
     $result = $doc->loadHTMLFile("");
-} catch (ValueError $e) {
-    echo $e->getMessage() . "\n";
+} catch (Throwable $e) {
+    echo $e::class, ': ', $e->getMessage(), "\n";
 }

 $doc = new DOMDocument();
 try {
     $result = $doc->loadHTMLFile("text.html\0something");
-} catch (ValueError $e) {
-    echo $e->getMessage() . "\n";
+} catch (Throwable $e) {
+    echo $e::class, ': ', $e->getMessage(), "\n";
 }
 ?>
 --EXPECT--
-DOMDocument::loadHTMLFile(): Argument #1 ($filename) must not be empty
-DOMDocument::loadHTMLFile(): Argument #1 ($filename) must not contain any null bytes
+ValueError: DOMDocument::loadHTMLFile(): Argument #1 ($filename) must not be empty
+ValueError: DOMDocument::loadHTMLFile(): Argument #1 ($filename) must not contain any null bytes
diff --git a/ext/dom/tests/DOMDocument_loadXML_error6.phpt b/ext/dom/tests/DOMDocument_loadXML_error6.phpt
index 748a8eb5dc1..04a01530a0c 100644
--- a/ext/dom/tests/DOMDocument_loadXML_error6.phpt
+++ b/ext/dom/tests/DOMDocument_loadXML_error6.phpt
@@ -8,9 +8,9 @@
 $dom = new DOMDocument();
 try {
     $dom->loadXML("");
-} catch (ValueError $exception) {
-    echo $exception->getMessage() . "\n";
+} catch (Throwable $exception) {
+    echo $exception::class, ': ', $exception->getMessage(), "\n";
 }
 ?>
 --EXPECT--
-DOMDocument::loadXML(): Argument #1 ($source) must not be empty
+ValueError: DOMDocument::loadXML(): Argument #1 ($source) must not be empty
diff --git a/ext/dom/tests/DOMDocument_load_error6.phpt b/ext/dom/tests/DOMDocument_load_error6.phpt
index a4f9bc4a02a..05da066d4e8 100644
--- a/ext/dom/tests/DOMDocument_load_error6.phpt
+++ b/ext/dom/tests/DOMDocument_load_error6.phpt
@@ -8,20 +8,20 @@
 $dom = new DOMDocument();
 try {
     $dom->load("");
-} catch (ValueError $exception) {
-    echo $exception->getMessage() . "\n";
+} catch (Throwable $exception) {
+    echo $exception::class, ': ', $exception->getMessage(), "\n";
 }

 try {
     $dom->load("/path/with/\0/byte");
-} catch (ValueError $exception) {
-    echo $exception->getMessage() . "\n";
+} catch (Throwable $exception) {
+    echo $exception::class, ': ', $exception->getMessage(), "\n";
 }

 // Path is too long
 var_dump($dom->load(str_repeat(" ", PHP_MAXPATHLEN + 1)));
 ?>
 --EXPECT--
-DOMDocument::load(): Argument #1 ($filename) must not be empty
-DOMDocument::load(): Argument #1 ($filename) must not contain any null bytes
+ValueError: DOMDocument::load(): Argument #1 ($filename) must not be empty
+ValueError: DOMDocument::load(): Argument #1 ($filename) must not contain any null bytes
 bool(false)
diff --git a/ext/dom/tests/DOMDocument_saveHTMLFile_error2.phpt b/ext/dom/tests/DOMDocument_saveHTMLFile_error2.phpt
index 248ed48345a..5288864e6e1 100644
--- a/ext/dom/tests/DOMDocument_saveHTMLFile_error2.phpt
+++ b/ext/dom/tests/DOMDocument_saveHTMLFile_error2.phpt
@@ -9,9 +9,9 @@
 <?php
 try {
     DOMDocument::saveHTMLFile();
-} catch (Error $e) {
-    echo $e->getMessage();
+} catch (Throwable $e) {
+    echo $e::class, ': ', $e->getMessage(), "\n";
 }
 ?>
 --EXPECT--
-Non-static method DOMDocument::saveHTMLFile() cannot be called statically
+Error: Non-static method DOMDocument::saveHTMLFile() cannot be called statically
diff --git a/ext/dom/tests/DOMDocument_saveHTMLFile_invalid_filename.phpt b/ext/dom/tests/DOMDocument_saveHTMLFile_invalid_filename.phpt
index 8dc89f25301..a4fec56433c 100644
--- a/ext/dom/tests/DOMDocument_saveHTMLFile_invalid_filename.phpt
+++ b/ext/dom/tests/DOMDocument_saveHTMLFile_invalid_filename.phpt
@@ -19,9 +19,9 @@
 $text = $title->appendChild($text);
 try {
     $doc->saveHTMLFile($filename);
-} catch (ValueError $exception) {
-    echo $exception->getMessage() . "\n";
+} catch (Throwable $exception) {
+    echo $exception::class, ': ', $exception->getMessage(), "\n";
 }
 ?>
 --EXPECT--
-DOMDocument::saveHTMLFile(): Argument #1 ($filename) must not be empty
+ValueError: DOMDocument::saveHTMLFile(): Argument #1 ($filename) must not be empty
diff --git a/ext/dom/tests/DOMDocument_saveHTML_error2.phpt b/ext/dom/tests/DOMDocument_saveHTML_error2.phpt
index 5e6fd098710..6f7093d6102 100644
--- a/ext/dom/tests/DOMDocument_saveHTML_error2.phpt
+++ b/ext/dom/tests/DOMDocument_saveHTML_error2.phpt
@@ -9,9 +9,9 @@
 <?php
 try {
     DOMDocument::saveHTML(true);
-} catch (Error $e) {
-    echo $e->getMessage();
+} catch (Throwable $e) {
+    echo $e::class, ': ', $e->getMessage(), "\n";
 }
 ?>
 --EXPECT--
-Non-static method DOMDocument::saveHTML() cannot be called statically
+Error: Non-static method DOMDocument::saveHTML() cannot be called statically
diff --git a/ext/dom/tests/DOMDocument_schemaValidateSource_error3.phpt b/ext/dom/tests/DOMDocument_schemaValidateSource_error3.phpt
index ec295a55e33..0aa33d74d7f 100644
--- a/ext/dom/tests/DOMDocument_schemaValidateSource_error3.phpt
+++ b/ext/dom/tests/DOMDocument_schemaValidateSource_error3.phpt
@@ -14,10 +14,10 @@

 try {
     $doc->schemaValidateSource('');
-} catch (ValueError $e) {
-    echo $e->getMessage() . "\n";
+} catch (Throwable $e) {
+    echo $e::class, ': ', $e->getMessage(), "\n";
 }

 ?>
 --EXPECT--
-DOMDocument::schemaValidateSource(): Argument #1 ($source) must not be empty
+ValueError: DOMDocument::schemaValidateSource(): Argument #1 ($source) must not be empty
diff --git a/ext/dom/tests/DOMDocument_schemaValidate_error3.phpt b/ext/dom/tests/DOMDocument_schemaValidate_error3.phpt
index 274463e62e1..686952b197c 100644
--- a/ext/dom/tests/DOMDocument_schemaValidate_error3.phpt
+++ b/ext/dom/tests/DOMDocument_schemaValidate_error3.phpt
@@ -14,10 +14,10 @@

 try {
     $doc->schemaValidate('');
-} catch (ValueError $e) {
-    echo $e->getMessage() . "\n";
+} catch (Throwable $e) {
+    echo $e::class, ': ', $e->getMessage(), "\n";
 }

 ?>
 --EXPECT--
-DOMDocument::schemaValidate(): Argument #1 ($filename) must not be empty
+ValueError: DOMDocument::schemaValidate(): Argument #1 ($filename) must not be empty
diff --git a/ext/dom/tests/DOMDocument_schemaValidate_error6.phpt b/ext/dom/tests/DOMDocument_schemaValidate_error6.phpt
index c5d99b20a3f..3407640c66b 100644
--- a/ext/dom/tests/DOMDocument_schemaValidate_error6.phpt
+++ b/ext/dom/tests/DOMDocument_schemaValidate_error6.phpt
@@ -11,15 +11,15 @@

 try {
     $doc->schemaValidate("/path/with/\0/byte");
-} catch (ValueError $e) {
-    echo $e->getMessage() . "\n";
+} catch (Throwable $e) {
+    echo $e::class, ': ', $e->getMessage(), "\n";
 }

 var_dump($doc->schemaValidate(str_repeat(" ", PHP_MAXPATHLEN + 1)));

 ?>
 --EXPECTF--
-DOMDocument::schemaValidate(): Argument #1 ($filename) must not contain any null bytes
+ValueError: DOMDocument::schemaValidate(): Argument #1 ($filename) must not contain any null bytes

 Warning: DOMDocument::schemaValidate(): Invalid Schema file source in %s on line %d
 bool(false)
diff --git a/ext/dom/tests/DOMDocument_strictErrorChecking_variation.phpt b/ext/dom/tests/DOMDocument_strictErrorChecking_variation.phpt
index b44d6395c30..3b2d3c8fc4f 100644
--- a/ext/dom/tests/DOMDocument_strictErrorChecking_variation.phpt
+++ b/ext/dom/tests/DOMDocument_strictErrorChecking_variation.phpt
@@ -19,9 +19,9 @@
 echo "Should throw DOMException when strictErrorChecking is on\n";
 try {
     $attr = $doc->createAttribute(0);
-} catch (DOMException $e) {
+} catch (Throwable $e) {
     echo "GOOD. DOMException thrown\n";
-    echo $e->getMessage() ."\n";
+    echo $e::class, ': ', $e->getMessage(), "\n";
 } catch (Exception $e) {
     echo "OOPS. Other exception thrown\n";
 }
@@ -36,9 +36,9 @@
 echo "Should raise PHP error because strictErrorChecking is off\n";
 try {
     $attr = $doc->createAttribute(0);
-} catch (DOMException $e) {
+} catch (Throwable $e) {
     echo "OOPS. DOMException thrown\n";
-    echo $e->getMessage() ."\n";
+    echo $e::class, ': ', $e->getMessage(), "\n";
 } catch (Exception $e) {
     echo "OOPS. Other exception thrown\n";
 }
@@ -50,7 +50,7 @@
 bool(true)
 Should throw DOMException when strictErrorChecking is on
 GOOD. DOMException thrown
-Invalid Character Error
+DOMException: Invalid Character Error
 Turn strictErrorChecking off
 See if strictErrorChecking is off
 bool(false)
diff --git a/ext/dom/tests/DOMDocument_validate_error2.phpt b/ext/dom/tests/DOMDocument_validate_error2.phpt
index ccf59ddaebe..bfd952d8149 100644
--- a/ext/dom/tests/DOMDocument_validate_error2.phpt
+++ b/ext/dom/tests/DOMDocument_validate_error2.phpt
@@ -9,9 +9,9 @@
 <?php
 try {
     DOMDocument::validate();
-} catch (Error $e) {
-    echo $e->getMessage();
+} catch (Throwable $e) {
+    echo $e::class, ': ', $e->getMessage(), "\n";
 }
 ?>
 --EXPECT--
-Non-static method DOMDocument::validate() cannot be called statically
+Error: Non-static method DOMDocument::validate() cannot be called statically
diff --git a/ext/dom/tests/DOMDocument_version_write.phpt b/ext/dom/tests/DOMDocument_version_write.phpt
index 3f594cb7e4b..ca6f88f8ac5 100644
--- a/ext/dom/tests/DOMDocument_version_write.phpt
+++ b/ext/dom/tests/DOMDocument_version_write.phpt
@@ -18,8 +18,8 @@ public function __toString(): string {

 try {
     $dom->version = new MyThrowingStringable;
-} catch (Exception $e) {
-    echo $e->getMessage(), "\n";
+} catch (Throwable $e) {
+    echo $e::class, ': ', $e->getMessage(), "\n";
 }
 var_dump($dom->version);
 echo $dom->saveXML();
@@ -28,6 +28,6 @@ public function __toString(): string {
 string(3) "1.0"
 string(6) "foobar"
 <?xml version="foobar"?>
-An exception was thrown
+Exception: An exception was thrown
 string(6) "foobar"
 <?xml version="foobar"?>
diff --git a/ext/dom/tests/DOMElement_append_hierarchy_test.phpt b/ext/dom/tests/DOMElement_append_hierarchy_test.phpt
index 63583c05bf5..2c17d887e0a 100644
--- a/ext/dom/tests/DOMElement_append_hierarchy_test.phpt
+++ b/ext/dom/tests/DOMElement_append_hierarchy_test.phpt
@@ -41,8 +41,8 @@
 $b_hello = $dom->firstChild->firstChild;
 try {
     $b_hello->append($b_hello);
-} catch (\DOMException $e) {
-    echo $e->getMessage(), "\n";
+} catch (\Throwable $e) {
+    echo $e::class, ': ', $e->getMessage(), "\n";
 }
 var_dump($dom->saveHTML());

@@ -51,8 +51,8 @@
 $b_hello = $dom->firstChild->firstChild;
 try {
     $b_hello->append($b_hello, "foo");
-} catch (\DOMException $e) {
-    echo $e->getMessage(), "\n";
+} catch (\Throwable $e) {
+    echo $e::class, ': ', $e->getMessage(), "\n";
 }
 var_dump($dom->saveHTML());

@@ -62,8 +62,8 @@
 $b_world = $b_hello->nextSibling;
 try {
     $b_world->firstChild->append($b_world);
-} catch (\DOMException $e) {
-    echo $e->getMessage(), "\n";
+} catch (\Throwable $e) {
+    echo $e::class, ': ', $e->getMessage(), "\n";
 }
 var_dump($dom->saveHTML());

@@ -73,8 +73,8 @@
 $dom2->loadXML('<p>other</p>');
 try {
     $dom->firstChild->firstChild->prepend($dom2->firstChild);
-} catch (\DOMException $e) {
-    echo $e->getMessage(), "\n";
+} catch (\Throwable $e) {
+    echo $e::class, ': ', $e->getMessage(), "\n";
 }
 var_dump($dom2->saveHTML());
 var_dump($dom->saveHTML());
@@ -94,19 +94,19 @@
 string(39) "<p><b><i>world<b>hello</b></i></b></p>
 "
 -- Append hello with itself --
-Hierarchy Request Error
+DOMException: Hierarchy Request Error
 string(39) "<p><b>hello</b><b><i>world</i></b></p>
 "
 -- Append hello with itself and text --
-Hierarchy Request Error
+DOMException: Hierarchy Request Error
 string(27) "<p><b><i>world</i></b></p>
 "
 -- Append world's i tag with the parent --
-Hierarchy Request Error
+DOMException: Hierarchy Request Error
 string(39) "<p><b>hello</b><b><i>world</i></b></p>
 "
 -- Append from another document --
-Wrong Document Error
+DOMException: Wrong Document Error
 string(13) "<p>other</p>
 "
 string(39) "<p><b>hello</b><b><i>world</i></b></p>
diff --git a/ext/dom/tests/DOMElement_className.phpt b/ext/dom/tests/DOMElement_className.phpt
index fb19f0e2302..184726e1f4e 100644
--- a/ext/dom/tests/DOMElement_className.phpt
+++ b/ext/dom/tests/DOMElement_className.phpt
@@ -28,7 +28,7 @@ public function __toString(): string {
 try {
     $dom->documentElement->className = new MyStringable();
 } catch (Throwable $e) {
-    echo "Error: ", $e->getMessage(), "\n";
+    echo $e::class, ': ', $e->getMessage(), "\n";
 }
 var_dump($dom->documentElement->className);
 echo $dom->saveXML();
@@ -41,7 +41,7 @@ public function __toString(): string {
 string(2) "é"
 string(0) ""
 string(5) "12345"
-Error: foo
+Exception: foo
 string(5) "12345"
 <?xml version="1.0"?>
 <html class="12345"/>
diff --git a/ext/dom/tests/DOMElement_id.phpt b/ext/dom/tests/DOMElement_id.phpt
index b406e3b4323..b810ba0fdb7 100644
--- a/ext/dom/tests/DOMElement_id.phpt
+++ b/ext/dom/tests/DOMElement_id.phpt
@@ -29,7 +29,7 @@ public function __toString(): string {
 try {
     $div->id = new MyStringable();
 } catch (Throwable $e) {
-    echo "Error: ", $e->getMessage(), "\n";
+    echo $e::class, ': ', $e->getMessage(), "\n";
 }
 var_dump($div->id);
 echo $dom->saveXML();
@@ -44,7 +44,7 @@ public function __toString(): string {
 string(2) "é"
 string(0) ""
 string(5) "12345"
-Error: foo
+Exception: foo
 string(5) "12345"
 <?xml version="1.0"?>
 <html><div id="12345"/></html>
diff --git a/ext/dom/tests/DOMElement_insertAdjacentElement.phpt b/ext/dom/tests/DOMElement_insertAdjacentElement.phpt
index 1e1eb1efece..a82458abafe 100644
--- a/ext/dom/tests/DOMElement_insertAdjacentElement.phpt
+++ b/ext/dom/tests/DOMElement_insertAdjacentElement.phpt
@@ -17,8 +17,8 @@

 try {
     var_dump($dom->createElement('free')->insertAdjacentElement("bogus", $dom->createElement('element')));
-} catch (DOMException $e) {
-    echo $e->getMessage(), "\n";
+} catch (Throwable $e) {
+    echo $e::class, ': ', $e->getMessage(), "\n";
 }

 echo "--- Hierarchy test ---\n";
@@ -28,8 +28,8 @@
 foreach (['beforebegin', 'afterbegin', 'beforeend', 'afterend'] as $where) {
     try {
         var_dump($child->insertAdjacentElement($where, $element)->tagName);
-    } catch (DOMException $e) {
-        echo $e->getMessage(), "\n";
+    } catch (Throwable $e) {
+        echo $e::class, ': ', $e->getMessage(), "\n";
     }
 }

@@ -84,12 +84,12 @@ function testNormalCases($dom, $uppercase) {
 --- Edge cases ---
 NULL
 NULL
-Syntax Error
+DOMException: Syntax Error
 --- Hierarchy test ---
-Hierarchy Request Error
-Hierarchy Request Error
-Hierarchy Request Error
-Hierarchy Request Error
+DOMException: Hierarchy Request Error
+DOMException: Hierarchy Request Error
+DOMException: Hierarchy Request Error
+DOMException: Hierarchy Request Error
 --- Normal cases uppercase ---
 string(1) "A"
 <?xml version="1.0"?>
diff --git a/ext/dom/tests/DOMElement_insertAdjacentText.phpt b/ext/dom/tests/DOMElement_insertAdjacentText.phpt
index 937f35f47ac..659ae53587a 100644
--- a/ext/dom/tests/DOMElement_insertAdjacentText.phpt
+++ b/ext/dom/tests/DOMElement_insertAdjacentText.phpt
@@ -12,8 +12,8 @@

 try {
     $dom->createElement('free')->insertAdjacentText("bogus", "bogus");
-} catch (DOMException $e) {
-    echo $e->getMessage(), "\n";
+} catch (Throwable $e) {
+    echo $e::class, ': ', $e->getMessage(), "\n";
 }

 function testNormalCases($dom, $uppercase) {
@@ -56,7 +56,7 @@ function testNormalCases($dom, $uppercase) {
 ?>
 --EXPECT--
 --- Edge cases ---
-Syntax Error
+DOMException: Syntax Error
 --- Normal cases uppercase ---
 <?xml version="1.0"?>
 <container>A<p>foo</p></container>
diff --git a/ext/dom/tests/DOMElement_prefix_empty.phpt b/ext/dom/tests/DOMElement_prefix_empty.phpt
index 8cd3515889e..a5150218a97 100644
--- a/ext/dom/tests/DOMElement_prefix_empty.phpt
+++ b/ext/dom/tests/DOMElement_prefix_empty.phpt
@@ -29,8 +29,8 @@

 try {
     $container->prefix = "conflict";
-} catch (DOMException $e) {
-    echo $e->getMessage(), "\n";
+} catch (Throwable $e) {
+    echo $e::class, ': ', $e->getMessage(), "\n";
 }
 echo $dom->saveXML();

@@ -46,6 +46,6 @@
 <?xml version="1.0"?>
 <hello:container xmlns:conflict="urn:foo" xmlns:hello="http://www.w3.org/1999/xhtml" xmlns="http://www.w3.org/1999/xhtml"/>
 --- Changing the prefix to that of a conflicting namespace ("conflict") ---
-Namespace Error
+DOMException: Namespace Error
 <?xml version="1.0"?>
 <hello:container xmlns:conflict="urn:foo" xmlns:hello="http://www.w3.org/1999/xhtml" xmlns="http://www.w3.org/1999/xhtml"/>
diff --git a/ext/dom/tests/DOMElement_prepend_hierarchy_test.phpt b/ext/dom/tests/DOMElement_prepend_hierarchy_test.phpt
index b1a9910e0ee..1dc34ffc473 100644
--- a/ext/dom/tests/DOMElement_prepend_hierarchy_test.phpt
+++ b/ext/dom/tests/DOMElement_prepend_hierarchy_test.phpt
@@ -48,8 +48,8 @@
 $b_hello = $dom->firstChild->firstChild;
 try {
     $b_hello->prepend($b_hello);
-} catch (\DOMException $e) {
-    echo $e->getMessage(), "\n";
+} catch (\Throwable $e) {
+    echo $e::class, ': ', $e->getMessage(), "\n";
 }
 var_dump($dom->saveHTML());

@@ -58,8 +58,8 @@
 $b_hello = $dom->firstChild->firstChild;
 try {
     $b_hello->prepend($b_hello, "foo");
-} catch (\DOMException $e) {
-    echo $e->getMessage(), "\n";
+} catch (\Throwable $e) {
+    echo $e::class, ': ', $e->getMessage(), "\n";
 }
 var_dump($dom->saveHTML());

@@ -69,8 +69,8 @@
 $b_world = $b_hello->nextSibling;
 try {
     $b_world->firstChild->prepend($b_world);
-} catch (\DOMException $e) {
-    echo $e->getMessage(), "\n";
+} catch (\Throwable $e) {
+    echo $e::class, ': ', $e->getMessage(), "\n";
 }
 var_dump($dom->saveHTML());

@@ -80,8 +80,8 @@
 $dom2->loadXML('<p>other</p>');
 try {
     $dom->firstChild->firstChild->prepend($dom2->firstChild);
-} catch (\DOMException $e) {
-    echo $e->getMessage(), "\n";
+} catch (\Throwable $e) {
+    echo $e::class, ': ', $e->getMessage(), "\n";
 }
 var_dump($dom2->saveHTML());
 var_dump($dom->saveHTML());
@@ -104,19 +104,19 @@
 string(42) "<p><b><i><b>hello</b>fooworld</i></b></p>
 "
 -- Prepend hello with itself --
-Hierarchy Request Error
+DOMException: Hierarchy Request Error
 string(39) "<p><b>hello</b><b><i>world</i></b></p>
 "
 -- Prepend hello with itself and text --
-Hierarchy Request Error
+DOMException: Hierarchy Request Error
 string(27) "<p><b><i>world</i></b></p>
 "
 -- Prepend world's i tag with the parent --
-Hierarchy Request Error
+DOMException: Hierarchy Request Error
 string(39) "<p><b>hello</b><b><i>world</i></b></p>
 "
 -- Append from another document --
-Wrong Document Error
+DOMException: Wrong Document Error
 string(13) "<p>other</p>
 "
 string(39) "<p><b>hello</b><b><i>world</i></b></p>
diff --git a/ext/dom/tests/DOMElement_replaceChildren.phpt b/ext/dom/tests/DOMElement_replaceChildren.phpt
index a28d9993418..3244462dc44 100644
--- a/ext/dom/tests/DOMElement_replaceChildren.phpt
+++ b/ext/dom/tests/DOMElement_replaceChildren.phpt
@@ -12,14 +12,14 @@

 try {
     $dom->documentElement->replaceChildren($dom->documentElement);
-} catch (DOMException $e) {
-    echo $e->getMessage(), "\n";
+} catch (Throwable $e) {
+    echo $e::class, ': ', $e->getMessage(), "\n";
 }

 try {
     $dom->documentElement->firstElementChild->replaceChildren($dom->documentElement);
-} catch (DOMException $e) {
-    echo $e->getMessage(), "\n";
+} catch (Throwable $e) {
+    echo $e::class, ': ', $e->getMessage(), "\n";
 }

 echo "--- Normal cases ---\n";
@@ -60,8 +60,8 @@
 ?>
 --EXPECT--
 --- Edge cases ---
-Hierarchy Request Error
-Hierarchy Request Error
+DOMException: Hierarchy Request Error
+DOMException: Hierarchy Request Error
 --- Normal cases ---
 <?xml version="1.0" standalone="yes"?>
 <!DOCTYPE HTML>
diff --git a/ext/dom/tests/DOMElement_toggleAttribute.phpt b/ext/dom/tests/DOMElement_toggleAttribute.phpt
index b9e9989e1fe..3fe061b2cdd 100644
--- a/ext/dom/tests/DOMElement_toggleAttribute.phpt
+++ b/ext/dom/tests/DOMElement_toggleAttribute.phpt
@@ -12,8 +12,8 @@

 try {
     var_dump($html->documentElement->toggleAttribute("\0"));
-} catch (DOMException $e) {
-    echo $e->getMessage(), "\n";
+} catch (Throwable $e) {
+    echo $e::class, ': ', $e->getMessage(), "\n";
 }

 echo "--- Selected attribute tests (HTML) ---\n";
@@ -88,7 +88,7 @@

 ?>
 --EXPECTF--
-Invalid Character Error
+DOMException: Invalid Character Error
 --- Selected attribute tests (HTML) ---
 bool(false)
 <!DOCTYPE HTML>
diff --git a/ext/dom/tests/DOMEntityReference_error1.phpt b/ext/dom/tests/DOMEntityReference_error1.phpt
index 1f805c1dbc8..eaf118a0b1d 100644
--- a/ext/dom/tests/DOMEntityReference_error1.phpt
+++ b/ext/dom/tests/DOMEntityReference_error1.phpt
@@ -6,11 +6,11 @@
 <?php
 try {
     new DOMEntityReference('!');
-} catch (DOMException $e) {
+} catch (Throwable $e) {
     var_dump($e->getCode() === DOM_INVALID_CHARACTER_ERR);
-    echo $e->getMessage();
+    echo $e::class, ': ', $e->getMessage(), "\n";
 }
 ?>
 --EXPECT--
 bool(true)
-Invalid Character Error
+DOMException: Invalid Character Error
diff --git a/ext/dom/tests/DOMNamedNodeMap_edge_case_offset.phpt b/ext/dom/tests/DOMNamedNodeMap_edge_case_offset.phpt
index 30a961143c7..4538112b4d6 100644
--- a/ext/dom/tests/DOMNamedNodeMap_edge_case_offset.phpt
+++ b/ext/dom/tests/DOMNamedNodeMap_edge_case_offset.phpt
@@ -13,17 +13,17 @@
 // Consistent with the method call
 try {
     var_dump($root->attributes[-1]);
-} catch (ValueError $e) {
-    echo $e->getMessage(), "\n";
+} catch (Throwable $e) {
+    echo $e::class, ': ', $e->getMessage(), "\n";
 }
 try {
     $root->attributes[][] = null;
 } catch (Throwable $e) {
-    echo $e->getMessage(), "\n";
+    echo $e::class, ': ', $e->getMessage(), "\n";
 }

 ?>
 --EXPECT--
 int(1)
-must be between 0 and 2147483647
-Cannot access DOMNamedNodeMap without offset
+ValueError: must be between 0 and 2147483647
+Error: Cannot access DOMNamedNodeMap without offset
diff --git a/ext/dom/tests/DOMNode_C14NFile_basic.phpt b/ext/dom/tests/DOMNode_C14NFile_basic.phpt
index fea039d3ca9..11d9874e42b 100644
--- a/ext/dom/tests/DOMNode_C14NFile_basic.phpt
+++ b/ext/dom/tests/DOMNode_C14NFile_basic.phpt
@@ -27,13 +27,13 @@
 var_dump($content);
 try {
     var_dump($node->C14NFile($output, false, false, []));
-} catch (\ValueError $e) {
-    echo $e->getMessage() . \PHP_EOL;
+} catch (\Throwable $e) {
+    echo $e::class, ': ', $e->getMessage(), "\n";
 }
 try {
     var_dump($node->C14NFile($output, false, false, ['query' => []]));
-} catch (\TypeError $e) {
-    echo $e->getMessage() . \PHP_EOL;
+} catch (\Throwable $e) {
+    echo $e::class, ': ', $e->getMessage(), "\n";
 }
 ?>
 --CLEAN--
@@ -44,5 +44,5 @@
 --EXPECT--
 int(34)
 string(34) "<title>The Grapes of Wrath</title>"
-DOMNode::C14NFile(): Argument #4 ($xpath) must have a "query" key
-DOMNode::C14NFile(): Argument #4 ($xpath) "query" option must be a string, array given
+ValueError: DOMNode::C14NFile(): Argument #4 ($xpath) must have a "query" key
+TypeError: DOMNode::C14NFile(): Argument #4 ($xpath) "query" option must be a string, array given
diff --git a/ext/dom/tests/DOMNode_C14N_basic.phpt b/ext/dom/tests/DOMNode_C14N_basic.phpt
index f936f9faa9a..f624070efcd 100644
--- a/ext/dom/tests/DOMNode_C14N_basic.phpt
+++ b/ext/dom/tests/DOMNode_C14N_basic.phpt
@@ -25,16 +25,16 @@

 try {
     var_dump($node->C14N(false, false, []));
-} catch (\ValueError $e) {
-    echo $e->getMessage() . \PHP_EOL;
+} catch (\Throwable $e) {
+    echo $e::class, ': ', $e->getMessage(), "\n";
 }
 try {
     var_dump($node->C14N(false, false, ['query' => []]));
-} catch (\TypeError $e) {
-    echo $e->getMessage() . \PHP_EOL;
+} catch (\Throwable $e) {
+    echo $e::class, ': ', $e->getMessage(), "\n";
 }
 ?>
 --EXPECT--
 string(34) "<title>The Grapes of Wrath</title>"
-DOMNode::C14N(): Argument #3 ($xpath) must have a "query" key
-DOMNode::C14N(): Argument #3 ($xpath) "query" option must be a string, array given
+ValueError: DOMNode::C14N(): Argument #3 ($xpath) must have a "query" key
+TypeError: DOMNode::C14N(): Argument #3 ($xpath) "query" option must be a string, array given
diff --git a/ext/dom/tests/DOMNode_contains.phpt b/ext/dom/tests/DOMNode_contains.phpt
index 5c18963804c..35a5240b124 100644
--- a/ext/dom/tests/DOMNode_contains.phpt
+++ b/ext/dom/tests/DOMNode_contains.phpt
@@ -34,8 +34,8 @@

 try {
     var_dump($dom->contains(new stdClass));
-} catch (TypeError $e) {
-    echo $e->getMessage(), "\n";
+} catch (Throwable $e) {
+    echo $e::class, ': ', $e->getMessage(), "\n";
 }

 echo "--- True cases ---\n";
@@ -78,7 +78,7 @@
 --EXPECT--
 --- False edge cases ---
 bool(false)
-DOMNode::contains(): Argument #1 ($other) must be of type DOMNode|DOMNameSpaceNode|null, stdClass given
+TypeError: DOMNode::contains(): Argument #1 ($other) must be of type DOMNode|DOMNameSpaceNode|null, stdClass given
 --- True cases ---
 bool(true)
 bool(true)
diff --git a/ext/dom/tests/DOMNode_insertBefore_error1.phpt b/ext/dom/tests/DOMNode_insertBefore_error1.phpt
index 9b42ef46c9e..1cc2d756836 100644
--- a/ext/dom/tests/DOMNode_insertBefore_error1.phpt
+++ b/ext/dom/tests/DOMNode_insertBefore_error1.phpt
@@ -15,10 +15,10 @@

 try {
     $node_in_doc2->insertBefore($node_in_doc1);
-} catch(DOMException $e) {
-    echo $e->getMessage();
+} catch(Throwable $e) {
+    echo $e::class, ': ', $e->getMessage(), "\n";
 }

 ?>
 --EXPECT--
-Wrong Document Error
+DOMException: Wrong Document Error
diff --git a/ext/dom/tests/DOMNode_insertBefore_error2.phpt b/ext/dom/tests/DOMNode_insertBefore_error2.phpt
index 317eb897919..761baf2c04c 100644
--- a/ext/dom/tests/DOMNode_insertBefore_error2.phpt
+++ b/ext/dom/tests/DOMNode_insertBefore_error2.phpt
@@ -27,10 +27,10 @@

 try {
     $parent_node->insertBefore($new_node, $ref_node);
-} catch(DOMException $e) {
-    echo $e->getMessage();
+} catch(Throwable $e) {
+    echo $e::class, ': ', $e->getMessage(), "\n";
 }

 ?>
 --EXPECT--
-Not Found Error
+DOMException: Not Found Error
diff --git a/ext/dom/tests/DOMNode_insertBefore_error3.phpt b/ext/dom/tests/DOMNode_insertBefore_error3.phpt
index 9fa25e3b2ac..6daf1046eda 100644
--- a/ext/dom/tests/DOMNode_insertBefore_error3.phpt
+++ b/ext/dom/tests/DOMNode_insertBefore_error3.phpt
@@ -28,10 +28,10 @@

 try {
     $parent_node->insertBefore($new_node, $ref_node);
-} catch(DOMException $e) {
-    echo $e->getMessage();
+} catch(Throwable $e) {
+    echo $e::class, ': ', $e->getMessage(), "\n";
 }

 ?>
 --EXPECT--
-Not Found Error
+DOMException: Not Found Error
diff --git a/ext/dom/tests/DOMNode_insertBefore_error4.phpt b/ext/dom/tests/DOMNode_insertBefore_error4.phpt
index 41838bb78a1..003c126a087 100644
--- a/ext/dom/tests/DOMNode_insertBefore_error4.phpt
+++ b/ext/dom/tests/DOMNode_insertBefore_error4.phpt
@@ -27,10 +27,10 @@

 try {
     $parent_node->insertBefore($new_node, $ref_node);
-} catch(DOMException $e) {
-    echo $e->getMessage();
+} catch(Throwable $e) {
+    echo $e::class, ': ', $e->getMessage(), "\n";
 }

 ?>
 --EXPECT--
-Not Found Error
+DOMException: Not Found Error
diff --git a/ext/dom/tests/DOMNode_insertBefore_error5.phpt b/ext/dom/tests/DOMNode_insertBefore_error5.phpt
index 17ac5382066..ae127b17e58 100644
--- a/ext/dom/tests/DOMNode_insertBefore_error5.phpt
+++ b/ext/dom/tests/DOMNode_insertBefore_error5.phpt
@@ -29,10 +29,10 @@

 try {
     $parent_node->insertBefore($new_node, $ref_node);
-} catch(DOMException $e) {
-    echo $e->getMessage();
+} catch(Throwable $e) {
+    echo $e::class, ': ', $e->getMessage(), "\n";
 }

 ?>
 --EXPECT--
-Not Found Error
+DOMException: Not Found Error
diff --git a/ext/dom/tests/DOMNode_insertBefore_error6.phpt b/ext/dom/tests/DOMNode_insertBefore_error6.phpt
index a8348791f17..ff0ae450f89 100644
--- a/ext/dom/tests/DOMNode_insertBefore_error6.phpt
+++ b/ext/dom/tests/DOMNode_insertBefore_error6.phpt
@@ -24,10 +24,10 @@

 try {
     $parent_node->insertBefore($new_node, $ref_node);
-} catch(DOMException $e) {
-    echo $e->getMessage();
+} catch(Throwable $e) {
+    echo $e::class, ': ', $e->getMessage(), "\n";
 }

 ?>
 --EXPECT--
-Not Found Error
+DOMException: Not Found Error
diff --git a/ext/dom/tests/DOMNode_removeChild_error1.phpt b/ext/dom/tests/DOMNode_removeChild_error1.phpt
index 05d3c31624f..5f8cf1ab519 100644
--- a/ext/dom/tests/DOMNode_removeChild_error1.phpt
+++ b/ext/dom/tests/DOMNode_removeChild_error1.phpt
@@ -13,8 +13,8 @@
 $parent->appendChild($child2);
 try {
 	$parent->removeChild($child1);
-} catch (DOMException $e) {
-	echo "DOMException: " . $e->getMessage();
+} catch (Throwable $e) {
+	echo $e::class, ': ', $e->getMessage(), "\n";
 }
 ?>
 --EXPECT--
diff --git a/ext/dom/tests/DOMNode_replaceChild_error1.phpt b/ext/dom/tests/DOMNode_replaceChild_error1.phpt
index f276fc8d207..2e050707c70 100644
--- a/ext/dom/tests/DOMNode_replaceChild_error1.phpt
+++ b/ext/dom/tests/DOMNode_replaceChild_error1.phpt
@@ -14,8 +14,8 @@
 $parent->appendChild($child2);
 try {
 	$parent->replaceChild($child3, $child1);
-} catch (DOMException $e) {
-	echo "DOMException: " . $e->getMessage();
+} catch (Throwable $e) {
+	echo $e::class, ': ', $e->getMessage(), "\n";
 }
 ?>
 --EXPECT--
diff --git a/ext/dom/tests/DOMNode_replaceChild_error2.phpt b/ext/dom/tests/DOMNode_replaceChild_error2.phpt
index 160838a537d..bf608b18151 100644
--- a/ext/dom/tests/DOMNode_replaceChild_error2.phpt
+++ b/ext/dom/tests/DOMNode_replaceChild_error2.phpt
@@ -12,8 +12,8 @@
 $b->appendChild($c);
 try {
 	$b->replaceChild($a, $c);
-} catch (DOMException $e) {
-	echo "DOMException: " . $e->getMessage();
+} catch (Throwable $e) {
+	echo $e::class, ': ', $e->getMessage(), "\n";
 }
 ?>
 --EXPECT--
diff --git a/ext/dom/tests/DOMProcessingInstruction.phpt b/ext/dom/tests/DOMProcessingInstruction.phpt
index ca79e31966e..2602c0f92b3 100644
--- a/ext/dom/tests/DOMProcessingInstruction.phpt
+++ b/ext/dom/tests/DOMProcessingInstruction.phpt
@@ -15,8 +15,8 @@ public function __toString(): string {

 try {
     $pi = new DOMProcessingInstruction("\0");
-} catch (DOMException $e) {
-    echo $e->getMessage(), "\n";
+} catch (Throwable $e) {
+    echo $e::class, ': ', $e->getMessage(), "\n";
 }

 $pi = new DOMProcessingInstruction("test");
@@ -30,7 +30,7 @@ public function __toString(): string {
 try {
     $pi->data = new FailingStringable;
 } catch (Throwable $e) {
-    echo $e->getMessage(), "\n";
+    echo $e::class, ': ', $e->getMessage(), "\n";
 }
 var_dump($pi->data);
 $pi->data = 12345;
@@ -53,28 +53,28 @@ public function __toString(): string {
 try {
     var_dump($instance->target);
 } catch (Throwable $e) {
-    echo $e->getMessage(), "\n";
+    echo $e::class, ': ', $e->getMessage(), "\n";
 }
 try {
     var_dump($instance->data);
 } catch (Throwable $e) {
-    echo $e->getMessage(), "\n";
+    echo $e::class, ': ', $e->getMessage(), "\n";
 }
 try {
     $instance->data = "hello";
 } catch (Throwable $e) {
-    echo $e->getMessage(), "\n";
+    echo $e::class, ': ', $e->getMessage(), "\n";
 }

 ?>
 --EXPECT--
 --- Test construction ---
-Invalid Character Error
+DOMException: Invalid Character Error
 --- Test fields ---
 string(4) "test"
 string(0) ""
 string(2) "ok"
-failed in __toString
+Exception: failed in __toString
 string(2) "ok"
 string(5) "12345"
 string(10) "my data <>"
@@ -82,6 +82,6 @@ public function __toString(): string {
 <?xml version="1.0"?>
 <root><?test my data <>?></root>
 --- Test construction with __construct by reflection and fields ---
-Invalid State Error
-Invalid State Error
-Invalid State Error
+DOMException: Invalid State Error
+DOMException: Invalid State Error
+DOMException: Invalid State Error
diff --git a/ext/dom/tests/DOMXPath_callables.phpt b/ext/dom/tests/DOMXPath_callables.phpt
index 3d20527475d..402d7b285a1 100644
--- a/ext/dom/tests/DOMXPath_callables.phpt
+++ b/ext/dom/tests/DOMXPath_callables.phpt
@@ -30,8 +30,8 @@ public function dummy(string $var) {
 $xpath->registerNamespace("php", "http://php.net/xpath");
 try {
     $xpath->evaluate("//a[php:function('var_dump', string(@href))]");
-} catch (Error $e) {
-    echo $e->getMessage(), "\n";
+} catch (Throwable $e) {
+    echo $e::class, ': ', $e->getMessage(), "\n";
 }

 echo "--- Legit cases: all ---\n";
@@ -55,7 +55,7 @@ public function dummy(string $var) {
 try {
     $xpath->evaluate("//a[php:function('notinset', string(@href))]");
 } catch (Throwable $e) {
-    echo $e->getMessage(), "\n";
+    echo $e::class, ': ', $e->getMessage(), "\n";
 }

 echo "--- Legit cases: set with cycle ---\n";
@@ -73,7 +73,7 @@ public function dummy(string $var) {
 ?>
 --EXPECT--
 --- Legit cases: none ---
-No callbacks were registered
+Error: No callbacks were registered
 --- Legit cases: all ---
 string(15) "https://php.net"
 string(15) "https://php.net"
@@ -81,7 +81,7 @@ public function dummy(string $var) {
 string(15) "https://php.net"
 string(15) "https://php.net"
 string(15) "https://php.net"
-No callback handler "notinset" registered
+Error: No callback handler "notinset" registered
 --- Legit cases: set with cycle ---
 dummy: https://php.net
 --- Legit cases: reset to null ---
diff --git a/ext/dom/tests/DOMXPath_callables_errors.phpt b/ext/dom/tests/DOMXPath_callables_errors.phpt
index 10019474e7e..a34427ebefd 100644
--- a/ext/dom/tests/DOMXPath_callables_errors.phpt
+++ b/ext/dom/tests/DOMXPath_callables_errors.phpt
@@ -11,50 +11,50 @@
 $xpath = new DOMXPath($doc);
 try {
     $xpath->registerPhpFunctions("nonexistent");
-} catch (TypeError $e) {
-    echo $e->getMessage(), "\n";
+} catch (Throwable $e) {
+    echo $e::class, ': ', $e->getMessage(), "\n";
 }

 try {
     $xpath->registerPhpFunctions(function () {});
-} catch (TypeError $e) {
-    echo $e->getMessage(), "\n";
+} catch (Throwable $e) {
+    echo $e::class, ': ', $e->getMessage(), "\n";
 }

 try {
     $xpath->registerPhpFunctions([function () {}]);
 } catch (Throwable $e) {
-    echo $e->getMessage(), "\n";
+    echo $e::class, ': ', $e->getMessage(), "\n";
 }

 try {
     $xpath->registerPhpFunctions([var_dump(...)]);
 } catch (Throwable $e) {
-    echo $e->getMessage(), "\n";
+    echo $e::class, ': ', $e->getMessage(), "\n";
 }

 try {
     $xpath->registerPhpFunctions(["nonexistent"]);
 } catch (Throwable $e) {
-    echo $e->getMessage(), "\n";
+    echo $e::class, ': ', $e->getMessage(), "\n";
 }

 try {
     $xpath->registerPhpFunctions(["" => var_dump(...)]);
 } catch (Throwable $e) {
-    echo $e->getMessage(), "\n";
+    echo $e::class, ': ', $e->getMessage(), "\n";
 }

 try {
     $xpath->registerPhpFunctions(["\0" => var_dump(...)]);
 } catch (Throwable $e) {
-    echo $e->getMessage(), "\n";
+    echo $e::class, ': ', $e->getMessage(), "\n";
 }

 try {
     $xpath->registerPhpFunctions("");
 } catch (Throwable $e) {
-    echo $e->getMessage(), "\n";
+    echo $e::class, ': ', $e->getMessage(), "\n";
 }

 $x = new class {
@@ -67,17 +67,17 @@ public static function dump() {}
     $str = str_repeat($classes[count($classes) - 1] . '::dump', random_int(1, 1));
     $xpath->registerPhpFunctions([$str]);
 } catch (Throwable $e) {
-    echo $e->getMessage(), "\n";
+    echo $e::class, ': ', $e->getMessage(), "\n";
 }

 ?>
 --EXPECT--
-DOMXPath::registerPhpFunctions(): Argument #1 ($restrict) must be a callable, function "nonexistent" not found or invalid function name
-DOMXPath::registerPhpFunctions(): Argument #1 ($restrict) must be of type array|string|null, Closure given
-Object of class Closure could not be converted to string
-Object of class Closure could not be converted to string
-DOMXPath::registerPhpFunctions(): Argument #1 ($restrict) must be an array with valid callbacks as values, function "nonexistent" not found or invalid function name
-DOMXPath::registerPhpFunctions(): Argument #1 ($restrict) must be an array containing valid callback names
-DOMXPath::registerPhpFunctions(): Argument #1 ($restrict) must be an array containing valid callback names
-DOMXPath::registerPhpFunctions(): Argument #1 ($restrict) must be a valid callback name
-DOMXPath::registerPhpFunctions(): Argument #1 ($restrict) must be an array containing valid callback names
+TypeError: DOMXPath::registerPhpFunctions(): Argument #1 ($restrict) must be a callable, function "nonexistent" not found or invalid function name
+TypeError: DOMXPath::registerPhpFunctions(): Argument #1 ($restrict) must be of type array|string|null, Closure given
+Error: Object of class Closure could not be converted to string
+Error: Object of class Closure could not be converted to string
+TypeError: DOMXPath::registerPhpFunctions(): Argument #1 ($restrict) must be an array with valid callbacks as values, function "nonexistent" not found or invalid function name
+ValueError: DOMXPath::registerPhpFunctions(): Argument #1 ($restrict) must be an array containing valid callback names
+ValueError: DOMXPath::registerPhpFunctions(): Argument #1 ($restrict) must be an array containing valid callback names
+ValueError: DOMXPath::registerPhpFunctions(): Argument #1 ($restrict) must be a valid callback name
+ValueError: DOMXPath::registerPhpFunctions(): Argument #1 ($restrict) must be an array containing valid callback names
diff --git a/ext/dom/tests/DOMXPath_clone.phpt b/ext/dom/tests/DOMXPath_clone.phpt
index 99cf1d4e08c..3d29b23cb81 100644
--- a/ext/dom/tests/DOMXPath_clone.phpt
+++ b/ext/dom/tests/DOMXPath_clone.phpt
@@ -13,10 +13,10 @@
 $xpath = new DOMXPath($dom);
 try {
     clone $xpath;
-} catch (Error $e) {
-    echo $e->getMessage(), "\n";
+} catch (Throwable $e) {
+    echo $e::class, ': ', $e->getMessage(), "\n";
 }

 ?>
 --EXPECT--
-Trying to clone an uncloneable object of class DOMXPath
+Error: Trying to clone an uncloneable object of class DOMXPath
diff --git a/ext/dom/tests/bug44648.phpt b/ext/dom/tests/bug44648.phpt
index 9dca0c9d70f..d9ac8b0ae5f 100644
--- a/ext/dom/tests/bug44648.phpt
+++ b/ext/dom/tests/bug44648.phpt
@@ -13,33 +13,33 @@
 try {
   $attr = new DOMAttr('@acb', '123');
   $root->setAttributeNode($attr);
-} catch (DOMException $e) {
-  echo $e->getMessage()."\n";
+} catch (Throwable $e) {
+  echo $e::class, ': ', $e->getMessage(), "\n";
 }

 try {
   $root->setAttribute('@def', '456');
-} catch (DOMException $e) {
-  echo $e->getMessage()."\n";
+} catch (Throwable $e) {
+  echo $e::class, ': ', $e->getMessage(), "\n";
 }

 try {
   $root->setAttributeNS(NULL, '@ghi', '789');
-} catch (DOMException $e) {
-  echo $e->getMessage()."\n";
+} catch (Throwable $e) {
+  echo $e::class, ': ', $e->getMessage(), "\n";
 }

 try {
   $root->setAttributeNS('urn::test', 'a:g@hi', '789');
-} catch (DOMException $e) {
-  echo $e->getMessage()."\n";
+} catch (Throwable $e) {
+  echo $e::class, ': ', $e->getMessage(), "\n";
 }

 echo $doc->saveXML($root);
 ?>
 --EXPECT--
-Invalid Character Error
-Invalid Character Error
-Invalid Character Error
-Namespace Error
+DOMException: Invalid Character Error
+DOMException: Invalid Character Error
+DOMException: Invalid Character Error
+DOMException: Namespace Error
 <root/>
diff --git a/ext/dom/tests/bug47430.phpt b/ext/dom/tests/bug47430.phpt
index f2428f73d3d..30c4b8703fb 100644
--- a/ext/dom/tests/bug47430.phpt
+++ b/ext/dom/tests/bug47430.phpt
@@ -13,8 +13,8 @@
 foreach ($elements as $i) {
     try {
         $i->previousSibling->nodeValue = '';
-    } catch (Error $e) {
-        echo $e->getMessage(), "\n";
+    } catch (Throwable $e) {
+        echo $e::class, ': ', $e->getMessage(), "\n";
     }
 }

@@ -25,8 +25,8 @@

 ?>
 --EXPECT--
-Attempt to assign property "nodeValue" on null
-Attempt to assign property "nodeValue" on null
+Error: Attempt to assign property "nodeValue" on null
+Error: Attempt to assign property "nodeValue" on null
 Array
 (
     [0] => Value
diff --git a/ext/dom/tests/bug66783.phpt b/ext/dom/tests/bug66783.phpt
index a9feba9529a..06649464ed7 100644
--- a/ext/dom/tests/bug66783.phpt
+++ b/ext/dom/tests/bug66783.phpt
@@ -9,9 +9,9 @@
 $e = $doc->createElement('e');
 try {
     $e->appendChild($doc);
-} catch (DOMException $ex) {
-    echo $ex->getMessage(), PHP_EOL;
+} catch (Throwable $ex) {
+    echo $ex::class, ': ', $ex->getMessage(), "\n";
 }
 ?>
 --EXPECT--
-Hierarchy Request Error
+DOMException: Hierarchy Request Error
diff --git a/ext/dom/tests/bug67949.phpt b/ext/dom/tests/bug67949.phpt
index f087633bdfe..8f1bd99ea09 100644
--- a/ext/dom/tests/bug67949.phpt
+++ b/ext/dom/tests/bug67949.phpt
@@ -45,8 +45,8 @@
 echo "--- testing read_dimension with null offset ---\n";
 try {
     var_dump($nodes[][] = 1);
-} catch (Error $e) {
-    echo $e->getMessage(), "\n";
+} catch (Throwable $e) {
+    echo $e::class, ': ', $e->getMessage(), "\n";
 }

 echo "--- testing attribute access ---\n";
@@ -87,7 +87,7 @@
 bool(false)
 NULL
 --- testing read_dimension with null offset ---
-Cannot access DOMNodeList without offset
+Error: Cannot access DOMNodeList without offset
 --- testing attribute access ---
 string(4) "href"
 ==DONE==
diff --git a/ext/dom/tests/bug77569.phpt b/ext/dom/tests/bug77569.phpt
index 68e6e87a04d..0ebf39f5946 100644
--- a/ext/dom/tests/bug77569.phpt
+++ b/ext/dom/tests/bug77569.phpt
@@ -8,9 +8,9 @@
 $dom = $imp->createDocument("", "");
 try {
     $dom->encoding = null;
-} catch (\ValueError $e) {
-    echo $e->getMessage() . \PHP_EOL;
+} catch (\Throwable $e) {
+    echo $e::class, ': ', $e->getMessage(), "\n";
 }
 ?>
 --EXPECT--
-Invalid document encoding
+ValueError: Invalid document encoding
diff --git a/ext/dom/tests/c14n_no_nodeset_returned.phpt b/ext/dom/tests/c14n_no_nodeset_returned.phpt
index 66efd8ba2b4..2fe203f3ecd 100644
--- a/ext/dom/tests/c14n_no_nodeset_returned.phpt
+++ b/ext/dom/tests/c14n_no_nodeset_returned.phpt
@@ -8,9 +8,9 @@
 $dom->loadXML('<root>test</root>');
 try {
     $dom->documentElement->C14N(true, false, ['query' => 'string(./root/text())']);
-} catch (Error $e) {
-    echo $e->getMessage(), "\n";
+} catch (Throwable $e) {
+    echo $e::class, ': ', $e->getMessage(), "\n";
 }
 ?>
 --EXPECT--
-XPath query did not return a nodeset
+Error: XPath query did not return a nodeset
diff --git a/ext/dom/tests/clone_list_map_collection.phpt b/ext/dom/tests/clone_list_map_collection.phpt
index 1eb91c46069..a093abe56fe 100644
--- a/ext/dom/tests/clone_list_map_collection.phpt
+++ b/ext/dom/tests/clone_list_map_collection.phpt
@@ -9,42 +9,42 @@
 $dom->loadXML('<root a="1"><a/></root>');
 try {
     clone $dom->documentElement->attributes;
-} catch (Error $e) {
-    echo $e->getMessage(), "\n";
+} catch (Throwable $e) {
+    echo $e::class, ': ', $e->getMessage(), "\n";
 }
 try {
     clone $dom->documentElement->childNodes;
-} catch (Error $e) {
-    echo $e->getMessage(), "\n";
+} catch (Throwable $e) {
+    echo $e::class, ': ', $e->getMessage(), "\n";
 }

 $dom = Dom\XMLDocument::createFromString('<!DOCTYPE root [<!ENTITY foo "">]><root a="1"><a/></root>');
 try {
     clone $dom->documentElement->attributes;
-} catch (Error $e) {
-    echo $e->getMessage(), "\n";
+} catch (Throwable $e) {
+    echo $e::class, ': ', $e->getMessage(), "\n";
 }
 try {
     clone $dom->documentElement->childNodes;
-} catch (Error $e) {
-    echo $e->getMessage(), "\n";
+} catch (Throwable $e) {
+    echo $e::class, ': ', $e->getMessage(), "\n";
 }
 try {
     clone $dom->documentElement->children;
-} catch (Error $e) {
-    echo $e->getMessage(), "\n";
+} catch (Throwable $e) {
+    echo $e::class, ': ', $e->getMessage(), "\n";
 }
 try {
     clone $dom->doctype->entities;
-} catch (Error $e) {
-    echo $e->getMessage(), "\n";
+} catch (Throwable $e) {
+    echo $e::class, ': ', $e->getMessage(), "\n";
 }

 ?>
 --EXPECT--
-Trying to clone an uncloneable object of class DOMNamedNodeMap
-Trying to clone an uncloneable object of class DOMNodeList
-Trying to clone an uncloneable object of class Dom\NamedNodeMap
-Trying to clone an uncloneable object of class Dom\NodeList
-Trying to clone an uncloneable object of class Dom\HTMLCollection
-Trying to clone an uncloneable object of class Dom\DtdNamedNodeMap
+Error: Trying to clone an uncloneable object of class DOMNamedNodeMap
+Error: Trying to clone an uncloneable object of class DOMNodeList
+Error: Trying to clone an uncloneable object of class Dom\NamedNodeMap
+Error: Trying to clone an uncloneable object of class Dom\NodeList
+Error: Trying to clone an uncloneable object of class Dom\HTMLCollection
+Error: Trying to clone an uncloneable object of class Dom\DtdNamedNodeMap
diff --git a/ext/dom/tests/delayed_freeing/direct_construction.phpt b/ext/dom/tests/delayed_freeing/direct_construction.phpt
index 5162d674017..6ec7bd72d7e 100644
--- a/ext/dom/tests/delayed_freeing/direct_construction.phpt
+++ b/ext/dom/tests/delayed_freeing/direct_construction.phpt
@@ -9,12 +9,12 @@ function node_alike_test($test) {
         var_dump($test->parentNode);
         var_dump($test->nodeValue);
     } catch (Throwable $e) {
-        echo $e->getMessage(), "\n";
+        echo $e::class, ': ', $e->getMessage(), "\n";
     }
     try {
         var_dump($test->appendChild($test));
     } catch (Throwable $e) {
-        echo $e->getMessage(), "\n";
+        echo $e::class, ': ', $e->getMessage(), "\n";
     }
 }

@@ -23,12 +23,12 @@ function node_alike_test($test) {
 try {
     var_dump($test->textContent);
 } catch (Throwable $e) {
-    echo $e->getMessage(), "\n";
+    echo $e::class, ': ', $e->getMessage(), "\n";
 }
 try {
     var_dump($test->appendData('test'));
 } catch (Throwable $e) {
-    echo $e->getMessage(), "\n";
+    echo $e::class, ': ', $e->getMessage(), "\n";
 }

 echo "-- Test DOMCdataSection --\n";
@@ -42,12 +42,12 @@ function node_alike_test($test) {
     var_dump($test->wholeText);
     var_dump($test->parentNode);
 } catch (Throwable $e) {
-    echo $e->getMessage(), "\n";
+    echo $e::class, ': ', $e->getMessage(), "\n";
 }
 try {
     var_dump($test->isWhitespaceInElementContent());
 } catch (Throwable $e) {
-    echo $e->getMessage(), "\n";
+    echo $e::class, ': ', $e->getMessage(), "\n";
 }

 echo "-- Test DOMComment --\n";
@@ -63,7 +63,7 @@ function node_alike_test($test) {
 try {
     var_dump($test->appendChild($test));
 } catch (Throwable $e) {
-    echo $e->getMessage(), "\n";
+    echo $e::class, ': ', $e->getMessage(), "\n";
 }

 echo "-- Test DOMNode --\n";
@@ -81,12 +81,12 @@ function node_alike_test($test) {
     var_dump($test->nodeValue);
     var_dump($test->parentNode);
 } catch (Throwable $e) {
-    echo $e->getMessage(), "\n";
+    echo $e::class, ': ', $e->getMessage(), "\n";
 }
 try {
     var_dump($test->appendChild($test));
 } catch (Throwable $e) {
-    echo $e->getMessage(), "\n";
+    echo $e::class, ': ', $e->getMessage(), "\n";
 }

 echo "-- Test DOMAttr --\n";
@@ -96,13 +96,13 @@ function node_alike_test($test) {
 try {
     var_dump($test->appendChild($test));
 } catch (Throwable $e) {
-    echo $e->getMessage(), "\n";
+    echo $e::class, ': ', $e->getMessage(), "\n";
 }
 ?>
 --EXPECT--
 -- Test DOMCharacterData --
-Invalid State Error
-Couldn't fetch DOMCharacterData
+DOMException: Invalid State Error
+Error: Couldn't fetch DOMCharacterData
 -- Test DOMCdataSection --
 string(4) "test"
 bool(true)
@@ -117,21 +117,21 @@ function node_alike_test($test) {
 -- Test DOMElement --
 string(4) "test"
 NULL
-No Modification Allowed Error
+DOMException: No Modification Allowed Error
 -- Test DOMNode --
-Invalid State Error
-Couldn't fetch DOMNode
+DOMException: Invalid State Error
+Error: Couldn't fetch DOMNode
 -- Test DOMNotation --
-Invalid State Error
-Couldn't fetch DOMNotation
+DOMException: Invalid State Error
+Error: Couldn't fetch DOMNotation
 -- Test DOMProcessingInstruction --
 NULL
 string(5) "value"
 bool(false)
 -- Test DOMEntity --
-Invalid State Error
-Couldn't fetch DOMEntity
+DOMException: Invalid State Error
+Error: Couldn't fetch DOMEntity
 -- Test DOMAttr --
 string(5) "value"
 NULL
-No Modification Allowed Error
+DOMException: No Modification Allowed Error
diff --git a/ext/dom/tests/delayed_freeing/without_contructor.phpt b/ext/dom/tests/delayed_freeing/without_contructor.phpt
index 4a5f63ed9ac..22b1c6cd556 100644
--- a/ext/dom/tests/delayed_freeing/without_contructor.phpt
+++ b/ext/dom/tests/delayed_freeing/without_contructor.phpt
@@ -11,14 +11,14 @@
 try {
     var_dump($node);
 } catch (Throwable $e) {
-    echo $e->getMessage(), "\n";
+    echo $e::class, ': ', $e->getMessage(), "\n";
 }

 // Call test
 try {
     $node->removeChild($node);
 } catch (Throwable $e) {
-    echo $e->getMessage(), "\n";
+    echo $e::class, ': ', $e->getMessage(), "\n";
 }

 // Import test
@@ -26,13 +26,13 @@
 try {
     $doc->appendChild($doc->importNode($node));
 } catch (Throwable $e) {
-    echo $e->getMessage(), "\n";
+    echo $e::class, ': ', $e->getMessage(), "\n";
 }

 ?>
 --EXPECT--
 object(DOMNode)#2 (0) {
 }
-Invalid State Error
-Couldn't fetch DOMNode
-Couldn't fetch DOMNode
+DOMException: Invalid State Error
+Error: Couldn't fetch DOMNode
+Error: Couldn't fetch DOMNode
diff --git a/ext/dom/tests/dom_import_simplexml.phpt b/ext/dom/tests/dom_import_simplexml.phpt
index e761bfa66d8..179ed7e65b5 100644
--- a/ext/dom/tests/dom_import_simplexml.phpt
+++ b/ext/dom/tests/dom_import_simplexml.phpt
@@ -16,8 +16,8 @@
 // This should fail because it has been imported already above in legacy DOM
 try {
     Dom\import_simplexml($s);
-} catch (TypeError $e) {
-    echo $e->getMessage(), "\n";
+} catch (Throwable $e) {
+    echo $e::class, ': ', $e->getMessage(), "\n";
 }
 ?>
 --EXPECT--
@@ -32,4 +32,4 @@
   <author>John Steinbeck</author>
  </book>
 </books>
-Dom\import_simplexml(): Argument #1 ($node) must not be already imported as a DOMNode
+TypeError: Dom\import_simplexml(): Argument #1 ($node) must not be already imported as a DOMNode
diff --git a/ext/dom/tests/dom_xinclude_errors.phpt b/ext/dom/tests/dom_xinclude_errors.phpt
index fe3addf8591..3c7b96993a3 100644
--- a/ext/dom/tests/dom_xinclude_errors.phpt
+++ b/ext/dom/tests/dom_xinclude_errors.phpt
@@ -14,10 +14,10 @@
 $dom = Dom\XMLDocument::createEmpty();
 try {
     $dom->xinclude(PHP_INT_MAX);
-} catch (ValueError $e) {
-    echo $e->getMessage();
+} catch (Throwable $e) {
+    echo $e::class, ': ', $e->getMessage(), "\n";
 }
 ?>
 --EXPECTF--
 Warning: DOMDocument::xinclude(): Invalid flags in %s on line %d
-Dom\XMLDocument::xinclude(): Argument #1 ($options) is too large
+ValueError: Dom\XMLDocument::xinclude(): Argument #1 ($options) is too large
diff --git a/ext/dom/tests/domxpath.phpt b/ext/dom/tests/domxpath.phpt
index cead1f8d5b7..19ee7633213 100644
--- a/ext/dom/tests/domxpath.phpt
+++ b/ext/dom/tests/domxpath.phpt
@@ -54,14 +54,14 @@ function MyAverage($nodelist) {
 try {
     $xpath->registerPHPFunctions('non_existent');
     $avg = $xpath->evaluate('number(php:function("non_existent", //def:testnode))');
-} catch (\Error $e) {
-    echo $e->getMessage() . \PHP_EOL;
+} catch (\Throwable $e) {
+    echo $e::class, ': ', $e->getMessage(), "\n";
 }
 try {
     $xpath->registerPhpFunctions(['non_existant']);
     $avg = $xpath->evaluate('number(php:function("non_existent", //def:testnode))');
-} catch (\Error $e) {
-    echo $e->getMessage() . \PHP_EOL;
+} catch (\Throwable $e) {
+    echo $e::class, ': ', $e->getMessage(), "\n";
 }
 ?>
 --EXPECT--
@@ -69,5 +69,5 @@ function MyAverage($nodelist) {
 float(1)
 bool(true)
 float(4)
-DOMXPath::registerPhpFunctions(): Argument #1 ($restrict) must be a callable, function "non_existent" not found or invalid function name
-DOMXPath::registerPhpFunctions(): Argument #1 ($restrict) must be an array with valid callbacks as values, function "non_existant" not found or invalid function name
+TypeError: DOMXPath::registerPhpFunctions(): Argument #1 ($restrict) must be a callable, function "non_existent" not found or invalid function name
+TypeError: DOMXPath::registerPhpFunctions(): Argument #1 ($restrict) must be an array with valid callbacks as values, function "non_existant" not found or invalid function name
diff --git a/ext/dom/tests/entity_reference_stale_02.phpt b/ext/dom/tests/entity_reference_stale_02.phpt
index 9e25a2c0e94..95abfb07ef5 100644
--- a/ext/dom/tests/entity_reference_stale_02.phpt
+++ b/ext/dom/tests/entity_reference_stale_02.phpt
@@ -26,8 +26,8 @@

 try {
     var_dump($iter->current()->publicId);
-} catch (Error $e) {
-    echo $e->getMessage(), "\n";
+} catch (Throwable $e) {
+    echo $e::class, ': ', $e->getMessage(), "\n";
 }

 ?>
diff --git a/ext/dom/tests/gh11830/attribute_variation.phpt b/ext/dom/tests/gh11830/attribute_variation.phpt
index 34a6f094f58..7c5281e1044 100644
--- a/ext/dom/tests/gh11830/attribute_variation.phpt
+++ b/ext/dom/tests/gh11830/attribute_variation.phpt
@@ -14,42 +14,42 @@

 try {
     $doc->documentElement->firstElementChild->prepend($doc->documentElement->attributes[0]);
-} catch (\DOMException $e) {
-    echo $e->getMessage(), "\n";
+} catch (\Throwable $e) {
+    echo $e::class, ': ', $e->getMessage(), "\n";
 }

 try {
     $doc->documentElement->firstElementChild->append($doc->documentElement->attributes[0]);
-} catch (\DOMException $e) {
-    echo $e->getMessage(), "\n";
+} catch (\Throwable $e) {
+    echo $e::class, ': ', $e->getMessage(), "\n";
 }

 try {
     $doc->documentElement->firstElementChild->before($doc->documentElement->attributes[0]);
-} catch (\DOMException $e) {
-    echo $e->getMessage(), "\n";
+} catch (\Throwable $e) {
+    echo $e::class, ': ', $e->getMessage(), "\n";
 }

 try {
     $doc->documentElement->firstElementChild->after($doc->documentElement->attributes[0]);
-} catch (\DOMException $e) {
-    echo $e->getMessage(), "\n";
+} catch (\Throwable $e) {
+    echo $e::class, ': ', $e->getMessage(), "\n";
 }

 try {
     $doc->documentElement->firstElementChild->replaceWith($doc->documentElement->attributes[0]);
-} catch (\DOMException $e) {
-    echo $e->getMessage(), "\n";
+} catch (\Throwable $e) {
+    echo $e::class, ': ', $e->getMessage(), "\n";
 }

 echo $doc->saveXML();
 ?>
 --EXPECT--
-Hierarchy Request Error
-Hierarchy Request Error
-Hierarchy Request Error
-Hierarchy Request Error
-Hierarchy Request Error
+DOMException: Hierarchy Request Error
+DOMException: Hierarchy Request Error
+DOMException: Hierarchy Request Error
+DOMException: Hierarchy Request Error
+DOMException: Hierarchy Request Error
 <?xml version="1.0"?>
 <container x="foo">
     <test/>
diff --git a/ext/dom/tests/gh11830/document_variation.phpt b/ext/dom/tests/gh11830/document_variation.phpt
index 1f291b94687..be7056d999c 100644
--- a/ext/dom/tests/gh11830/document_variation.phpt
+++ b/ext/dom/tests/gh11830/document_variation.phpt
@@ -26,8 +26,8 @@ function test($method) {

     try {
         $doc->documentElement->firstElementChild->$method($testElement, $otherElement);
-    } catch (\DOMException $e) {
-        echo $e->getMessage(), "\n";
+    } catch (\Throwable $e) {
+        echo $e::class, ': ', $e->getMessage(), "\n";
     }

     echo $otherDoc->saveXML();
@@ -41,7 +41,7 @@ function test($method) {
 test("replaceWith");
 ?>
 --EXPECT--
-Wrong Document Error
+DOMException: Wrong Document Error
 <?xml version="1.0"?>
 <other/>
 <?xml version="1.0"?>
@@ -49,7 +49,7 @@ function test($method) {
     <alone/>
     <child/>
 </container>
-Wrong Document Error
+DOMException: Wrong Document Error
 <?xml version="1.0"?>
 <other/>
 <?xml version="1.0"?>
@@ -57,7 +57,7 @@ function test($method) {
     <alone/>
     <child/>
 </container>
-Wrong Document Error
+DOMException: Wrong Document Error
 <?xml version="1.0"?>
 <other/>
 <?xml version="1.0"?>
@@ -65,7 +65,7 @@ function test($method) {
     <alone/>
     <child/>
 </container>
-Wrong Document Error
+DOMException: Wrong Document Error
 <?xml version="1.0"?>
 <other/>
 <?xml version="1.0"?>
@@ -73,7 +73,7 @@ function test($method) {
     <alone/>
     <child/>
 </container>
-Wrong Document Error
+DOMException: Wrong Document Error
 <?xml version="1.0"?>
 <other/>
 <?xml version="1.0"?>
diff --git a/ext/dom/tests/gh11830/hierarchy_variation.phpt b/ext/dom/tests/gh11830/hierarchy_variation.phpt
index 44306846187..7a8322e1fd1 100644
--- a/ext/dom/tests/gh11830/hierarchy_variation.phpt
+++ b/ext/dom/tests/gh11830/hierarchy_variation.phpt
@@ -20,8 +20,8 @@ function test($method) {

     try {
         $testElement->$method($alone, $container);
-    } catch (\DOMException $e) {
-        echo $e->getMessage(), "\n";
+    } catch (\Throwable $e) {
+        echo $e::class, ': ', $e->getMessage(), "\n";
     }

     echo $doc->saveXML();
@@ -34,13 +34,13 @@ function test($method) {
 test("replaceWith");
 ?>
 --EXPECT--
-Hierarchy Request Error
+DOMException: Hierarchy Request Error
 <?xml version="1.0"?>
-Hierarchy Request Error
+DOMException: Hierarchy Request Error
 <?xml version="1.0"?>
-Hierarchy Request Error
+DOMException: Hierarchy Request Error
 <?xml version="1.0"?>
-Hierarchy Request Error
+DOMException: Hierarchy Request Error
 <?xml version="1.0"?>
-Hierarchy Request Error
+DOMException: Hierarchy Request Error
 <?xml version="1.0"?>
diff --git a/ext/dom/tests/gh11830/type_variation.phpt b/ext/dom/tests/gh11830/type_variation.phpt
index 76732775e6d..d2366b678a5 100644
--- a/ext/dom/tests/gh11830/type_variation.phpt
+++ b/ext/dom/tests/gh11830/type_variation.phpt
@@ -17,42 +17,42 @@

 try {
     $doc->documentElement->firstElementChild->prepend($testElement, 0);
-} catch (\TypeError $e) {
-    echo $e->getMessage(), "\n";
+} catch (\Throwable $e) {
+    echo $e::class, ': ', $e->getMessage(), "\n";
 }

 try {
     $doc->documentElement->firstElementChild->append($testElement, true);
-} catch (\TypeError $e) {
-    echo $e->getMessage(), "\n";
+} catch (\Throwable $e) {
+    echo $e::class, ': ', $e->getMessage(), "\n";
 }

 try {
     $doc->documentElement->firstElementChild->before($testElement, null);
-} catch (\TypeError $e) {
-    echo $e->getMessage(), "\n";
+} catch (\Throwable $e) {
+    echo $e::class, ': ', $e->getMessage(), "\n";
 }

 try {
     $doc->documentElement->firstElementChild->after($testElement, new stdClass);
-} catch (\TypeError $e) {
-    echo $e->getMessage(), "\n";
+} catch (\Throwable $e) {
+    echo $e::class, ': ', $e->getMessage(), "\n";
 }

 try {
     $doc->documentElement->firstElementChild->replaceWith($testElement, []);
-} catch (\TypeError $e) {
-    echo $e->getMessage(), "\n";
+} catch (\Throwable $e) {
+    echo $e::class, ': ', $e->getMessage(), "\n";
 }

 echo $doc->saveXML();
 ?>
 --EXPECT--
-DOMElement::prepend(): Argument #2 must be of type DOMNode|string, int given
-DOMElement::append(): Argument #2 must be of type DOMNode|string, bool given
-DOMElement::before(): Argument #2 must be of type DOMNode|string, null given
-DOMElement::after(): Argument #2 must be of type DOMNode|string, stdClass given
-DOMElement::replaceWith(): Argument #2 must be of type DOMNode|string, array given
+TypeError: DOMElement::prepend(): Argument #2 must be of type DOMNode|string, int given
+TypeError: DOMElement::append(): Argument #2 must be of type DOMNode|string, bool given
+TypeError: DOMElement::before(): Argument #2 must be of type DOMNode|string, null given
+TypeError: DOMElement::after(): Argument #2 must be of type DOMNode|string, stdClass given
+TypeError: DOMElement::replaceWith(): Argument #2 must be of type DOMNode|string, array given
 <?xml version="1.0"?>
 <container>
     <test/>
diff --git a/ext/dom/tests/gh12002.phpt b/ext/dom/tests/gh12002.phpt
index 7d1ae944646..2512aa7d23f 100644
--- a/ext/dom/tests/gh12002.phpt
+++ b/ext/dom/tests/gh12002.phpt
@@ -15,24 +15,24 @@ function make_nonconst(string $x) {
 var_dump($dom->encoding);
 try {
     $dom->encoding = make_nonconst('foobar');
-} catch (ValueError $e) {
-    echo $e->getMessage(), "\n";
+} catch (Throwable $e) {
+    echo $e::class, ': ', $e->getMessage(), "\n";
 }
 var_dump($dom->encoding);
 $dom->encoding = make_nonconst('utf-16le');
 var_dump($dom->encoding);
 try {
     $dom->encoding = NULL;
-} catch (ValueError $e) {
-    echo $e->getMessage(), "\n";
+} catch (Throwable $e) {
+    echo $e::class, ': ', $e->getMessage(), "\n";
 }
 var_dump($dom->encoding);

 ?>
 --EXPECT--
 string(5) "utf-8"
-Invalid document encoding
+ValueError: Invalid document encoding
 string(5) "utf-8"
 string(8) "utf-16le"
-Invalid document encoding
+ValueError: Invalid document encoding
 string(8) "utf-16le"
diff --git a/ext/dom/tests/gh13960.phpt b/ext/dom/tests/gh13960.phpt
index fae628f49c0..0094c84eafb 100644
--- a/ext/dom/tests/gh13960.phpt
+++ b/ext/dom/tests/gh13960.phpt
@@ -9,9 +9,9 @@
 $xp = new DOMXPath($domd);
 try {
     $xp->query("//foo[contains(text(), " . $xp->quote("tes\x00t") . ")]");
-} catch (ValueError $e) {
-    echo $e->getMessage(), "\n";
+} catch (Throwable $e) {
+    echo $e::class, ': ', $e->getMessage(), "\n";
 }
 ?>
 --EXPECT--
-DOMXPath::quote(): Argument #1 ($str) must not contain any null bytes
+ValueError: DOMXPath::quote(): Argument #1 ($str) must not contain any null bytes
diff --git a/ext/dom/tests/gh15137.phpt b/ext/dom/tests/gh15137.phpt
index c5ce1aca75b..6013cee2a56 100644
--- a/ext/dom/tests/gh15137.phpt
+++ b/ext/dom/tests/gh15137.phpt
@@ -8,4 +8,3 @@
 ?>
 --EXPECT--
 string(0) ""
-
diff --git a/ext/dom/tests/gh15910.phpt b/ext/dom/tests/gh15910.phpt
index c9b14a0b866..249795c5a12 100644
--- a/ext/dom/tests/gh15910.phpt
+++ b/ext/dom/tests/gh15910.phpt
@@ -10,9 +10,9 @@
 $doc->appendChild($doc->createElement('container'));
 try {
     $doc->documentElement->setAttributeNodeNS($doc);
-} catch (Error $e) {
-    echo $e->getMessage(), "\n";
+} catch (Throwable $e) {
+    echo $e::class, ': ', $e->getMessage(), "\n";
 }
 ?>
 --EXPECT--
-DOMElement::setAttributeNodeNS(): Argument #1 ($attr) must be of type DOMAttr, DOMDocument given
+TypeError: DOMElement::setAttributeNodeNS(): Argument #1 ($attr) must be of type DOMAttr, DOMDocument given
diff --git a/ext/dom/tests/gh16039.phpt b/ext/dom/tests/gh16039.phpt
index 48a862eda7b..fc3f519e72c 100644
--- a/ext/dom/tests/gh16039.phpt
+++ b/ext/dom/tests/gh16039.phpt
@@ -9,23 +9,23 @@
 $element = $dom->appendChild($dom->createElement('root'));
 try {
     $element->prepend('x', new DOMEntity);
-} catch (DOMException $e) {
-    echo $e->getMessage(), "\n";
+} catch (Throwable $e) {
+    echo $e::class, ': ', $e->getMessage(), "\n";
 }
 echo $dom->saveXML();
 $dom->strictErrorChecking = false; // Should not have influence
 try {
     $element->prepend('x', new DOMEntity);
-} catch (DOMException $e) {
-    echo $e->getMessage(), "\n";
+} catch (Throwable $e) {
+    echo $e::class, ': ', $e->getMessage(), "\n";
 }
 echo $dom->saveXML();

 ?>
 --EXPECT--
-Invalid State Error
+DOMException: Invalid State Error
 <?xml version="1.0"?>
 <root/>
-Invalid State Error
+DOMException: Invalid State Error
 <?xml version="1.0"?>
 <root/>
diff --git a/ext/dom/tests/gh16151.phpt b/ext/dom/tests/gh16151.phpt
index e11d3df4a56..d2fd5d2915f 100644
--- a/ext/dom/tests/gh16151.phpt
+++ b/ext/dom/tests/gh16151.phpt
@@ -13,13 +13,13 @@

 try {
     $attr->insertBefore(new DOMComment("h"));
-} catch (DOMException $e) {
-    echo $e->getMessage(), "\n";
+} catch (Throwable $e) {
+    echo $e::class, ': ', $e->getMessage(), "\n";
 }
 try {
     $attr->appendChild(new DOMComment("h"));
-} catch (DOMException $e) {
-    echo $e->getMessage(), "\n";
+} catch (Throwable $e) {
+    echo $e::class, ': ', $e->getMessage(), "\n";
 }

 $attr->insertBefore($doc->createEntityReference('amp'));
@@ -29,7 +29,7 @@

 ?>
 --EXPECT--
-Hierarchy Request Error
-Hierarchy Request Error
+DOMException: Hierarchy Request Error
+DOMException: Hierarchy Request Error
 <?xml version="1.0"?>
 <N xmlns="y" c="n&amp;&amp;">W</N>
diff --git a/ext/dom/tests/gh16190.phpt b/ext/dom/tests/gh16190.phpt
index d3d83b5eb49..2e1877862a5 100644
--- a/ext/dom/tests/gh16190.phpt
+++ b/ext/dom/tests/gh16190.phpt
@@ -9,10 +9,10 @@
 $rm = new ReflectionMethod($doc, '__construct');
 try {
     $rm->invoke($doc);
-} catch (Error $e) {
-    echo $e->getMessage(), "\n";
+} catch (Throwable $e) {
+    echo $e::class, ': ', $e->getMessage(), "\n";
 }

 ?>
 --EXPECT--
-Cannot directly construct Dom\XMLDocument, use document methods instead
+Error: Cannot directly construct Dom\XMLDocument, use document methods instead
diff --git a/ext/dom/tests/gh16316.phpt b/ext/dom/tests/gh16316.phpt
index 43368746bc4..1ddf969ef59 100644
--- a/ext/dom/tests/gh16316.phpt
+++ b/ext/dom/tests/gh16316.phpt
@@ -12,14 +12,14 @@ public function __construct() {}
 $demo = new Demo;
 try {
     var_dump($demo);
-} catch (DOMException $e) {
-    echo $e->getMessage(), "\n";
+} catch (Throwable $e) {
+    echo $e::class, ': ', $e->getMessage(), "\n";
 }

 try {
     var_dump($demo->document);
-} catch (DOMException $e) {
-    echo $e->getMessage(), "\n";
+} catch (Throwable $e) {
+    echo $e::class, ': ', $e->getMessage(), "\n";
 }

 ?>
@@ -28,5 +28,5 @@ public function __construct() {}
   ["registerNodeNamespaces"]=>
   bool(true)
 }
-Invalid State Error
-Invalid State Error
+DOMException: Invalid State Error
+DOMException: Invalid State Error
diff --git a/ext/dom/tests/gh16465.phpt b/ext/dom/tests/gh16465.phpt
index b09f5de7dcc..492f86833a7 100644
--- a/ext/dom/tests/gh16465.phpt
+++ b/ext/dom/tests/gh16465.phpt
@@ -8,22 +8,22 @@
 $v10 = new DOMElement("a");
 try {
     $v10->getElementsByTagName("text\0something");
-} catch (ValueError $e) {
-    echo $e->getMessage(), "\n";
+} catch (Throwable $e) {
+    echo $e::class, ': ', $e->getMessage(), "\n";
 }
 try {
     $v10->getElementsByTagNameNS("", "text\0something");
-} catch (ValueError $e) {
-    echo $e->getMessage(), "\n";
+} catch (Throwable $e) {
+    echo $e::class, ': ', $e->getMessage(), "\n";
 }
 try {
     $v10->getElementsByTagNameNS("text\0something", "");
-} catch (ValueError $e) {
-    echo $e->getMessage(), "\n";
+} catch (Throwable $e) {
+    echo $e::class, ': ', $e->getMessage(), "\n";
 }

 ?>
 --EXPECT--
-DOMElement::getElementsByTagName(): Argument #1 ($qualifiedName) must not contain any null bytes
-DOMElement::getElementsByTagNameNS(): Argument #2 ($localName) must not contain any null bytes
-DOMElement::getElementsByTagNameNS(): Argument #1 ($namespace) must not contain any null bytes
+ValueError: DOMElement::getElementsByTagName(): Argument #1 ($qualifiedName) must not contain any null bytes
+ValueError: DOMElement::getElementsByTagNameNS(): Argument #2 ($localName) must not contain any null bytes
+ValueError: DOMElement::getElementsByTagNameNS(): Argument #1 ($namespace) must not contain any null bytes
diff --git a/ext/dom/tests/gh16533.phpt b/ext/dom/tests/gh16533.phpt
index dad40e88b4d..45850f00b4f 100644
--- a/ext/dom/tests/gh16533.phpt
+++ b/ext/dom/tests/gh16533.phpt
@@ -8,13 +8,13 @@
 $doc = new DOMDocument();
 try {
     $doc->appendChild($doc->createAttribute('foo'));
-} catch (DOMException $e) {
-    echo $e->getMessage(), "\n";
+} catch (Throwable $e) {
+    echo $e::class, ': ', $e->getMessage(), "\n";
 }

 echo $doc->saveXML();

 ?>
 --EXPECT--
-Hierarchy Request Error
+DOMException: Hierarchy Request Error
 <?xml version="1.0"?>
diff --git a/ext/dom/tests/gh16535.phpt b/ext/dom/tests/gh16535.phpt
index adb1dfa91f2..0e743dd70c0 100644
--- a/ext/dom/tests/gh16535.phpt
+++ b/ext/dom/tests/gh16535.phpt
@@ -11,15 +11,15 @@
 $v4 = $v2->createElement('foo');
 try {
     $v4->appendChild($v2);
-} catch (DOMException $e) {
-    echo $e->getMessage(), "\n";
+} catch (Throwable $e) {
+    echo $e::class, ': ', $e->getMessage(), "\n";
 }
 $v2->loadHTML("<p>oU</p>");
 echo $v2->saveXML();

 ?>
 --EXPECT--
-Hierarchy Request Error
+DOMException: Hierarchy Request Error
 <?xml version="1.0" standalone="yes"?>
 <!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN" "http://www.w3.org/TR/REC-html40/loose.dtd">
 <html><body><p>oU</p></body></html>
diff --git a/ext/dom/tests/gh16593.phpt b/ext/dom/tests/gh16593.phpt
index 416d794a4f0..ed108513dce 100644
--- a/ext/dom/tests/gh16593.phpt
+++ b/ext/dom/tests/gh16593.phpt
@@ -10,13 +10,13 @@
 $child = $root->appendChild($doc->createElement('child'));
 try {
     $root->replaceChild($doc->createAttribute('foo'), $child);
-} catch (DOMException $e) {
-    echo $e->getMessage(), "\n";
+} catch (Throwable $e) {
+    echo $e::class, ': ', $e->getMessage(), "\n";
 }
 echo $doc->saveXML();

 ?>
 --EXPECT--
-Hierarchy Request Error
+DOMException: Hierarchy Request Error
 <?xml version="1.0"?>
 <root><child/></root>
diff --git a/ext/dom/tests/gh16594.phpt b/ext/dom/tests/gh16594.phpt
index adfde5948ee..aef53dd83f6 100644
--- a/ext/dom/tests/gh16594.phpt
+++ b/ext/dom/tests/gh16594.phpt
@@ -16,10 +16,10 @@

 try {
     $v1->before($v6);
-} catch (DOMException $e) {
-    echo $e->getMessage(), "\n";
+} catch (Throwable $e) {
+    echo $e::class, ': ', $e->getMessage(), "\n";
 }

 ?>
 --EXPECT--
-Hierarchy Request Error
+DOMException: Hierarchy Request Error
diff --git a/ext/dom/tests/gh16777_1.phpt b/ext/dom/tests/gh16777_1.phpt
index d821842ace4..be2dc88a0f4 100644
--- a/ext/dom/tests/gh16777_1.phpt
+++ b/ext/dom/tests/gh16777_1.phpt
@@ -13,12 +13,12 @@
 $dom2 = new DOMDocument();
 try {
     $dom2->appendChild($text);
-} catch (DOMException $e) {
-    echo $e->getMessage(), "\n";
+} catch (Throwable $e) {
+    echo $e::class, ': ', $e->getMessage(), "\n";
 }
 ?>
 --EXPECT--
 <?xml version="1.0"?>
 my value
 my new value
-Wrong Document Error
+DOMException: Wrong Document Error
diff --git a/ext/dom/tests/gh16777_2.phpt b/ext/dom/tests/gh16777_2.phpt
index a6f3a59621b..b0f1506c855 100644
--- a/ext/dom/tests/gh16777_2.phpt
+++ b/ext/dom/tests/gh16777_2.phpt
@@ -14,8 +14,8 @@
 $dom2 = new DOMDocument();
 try {
     $dom2->appendChild($el);
-} catch (DOMException $e) {
-    echo $e->getMessage(), "\n";
+} catch (Throwable $e) {
+    echo $e::class, ': ', $e->getMessage(), "\n";
 }
 var_dump($child->ownerDocument === $doc);
 ?>
@@ -23,5 +23,5 @@
 <?xml version="1.0"?>
 <name><child/></name>
 <newname/>
-Wrong Document Error
+DOMException: Wrong Document Error
 bool(true)
diff --git a/ext/dom/tests/gh17847.phpt b/ext/dom/tests/gh17847.phpt
index b2c4caff2fc..625a041ce7d 100644
--- a/ext/dom/tests/gh17847.phpt
+++ b/ext/dom/tests/gh17847.phpt
@@ -37,16 +37,16 @@
 foreach ($garbage as $node) {
     try {
         var_dump($node->localName);
-    } catch (DOMException $e) {
-        echo $e->getMessage(), "\n";
+    } catch (Throwable $e) {
+        echo $e::class, ': ', $e->getMessage(), "\n";
     }
 }
 ?>
 --EXPECT--
-Invalid State Error
-Invalid State Error
-Invalid State Error
-Invalid State Error
-Invalid State Error
-Invalid State Error
-Invalid State Error
+DOMException: Invalid State Error
+DOMException: Invalid State Error
+DOMException: Invalid State Error
+DOMException: Invalid State Error
+DOMException: Invalid State Error
+DOMException: Invalid State Error
+DOMException: Invalid State Error
diff --git a/ext/dom/tests/modern/common/template_rename.phpt b/ext/dom/tests/modern/common/template_rename.phpt
index a71126b21f2..04e1d8a00af 100644
--- a/ext/dom/tests/modern/common/template_rename.phpt
+++ b/ext/dom/tests/modern/common/template_rename.phpt
@@ -19,8 +19,8 @@

 try {
     $template->rename($template->namespaceURI, 'screwthis');
-} catch (DOMException $e) {
-    echo $e->getMessage(), "\n";
+} catch (Throwable $e) {
+    echo $e::class, ': ', $e->getMessage(), "\n";
 }

 // These shouldn't be changed!
@@ -30,6 +30,6 @@
 ?>
 --EXPECT--
 string(16) "a<div>foo</div>b"
-It is not possible to rename the template element because it hosts a document fragment
+DOMException: It is not possible to rename the template element because it hosts a document fragment
 string(8) "TEMPLATE"
 string(16) "a<div>foo</div>b"
diff --git a/ext/dom/tests/modern/css_selectors/closest_invalid_selector.phpt b/ext/dom/tests/modern/css_selectors/closest_invalid_selector.phpt
index 81db6a72b68..83940435a53 100644
--- a/ext/dom/tests/modern/css_selectors/closest_invalid_selector.phpt
+++ b/ext/dom/tests/modern/css_selectors/closest_invalid_selector.phpt
@@ -9,10 +9,10 @@

 try {
   var_dump($dom->documentElement->closest('@invalid'));
-} catch (DOMException $e) {
-  echo $e->getMessage();
+} catch (Throwable $e) {
+  echo $e::class, ': ', $e->getMessage(), "\n";
 }

 ?>
 --EXPECT--
-Invalid selector (Selectors. Unexpected token: @invalid)
+DOMException: Invalid selector (Selectors. Unexpected token: @invalid)
diff --git a/ext/dom/tests/modern/css_selectors/combinators.phpt b/ext/dom/tests/modern/css_selectors/combinators.phpt
index b43b07f59e8..02e026da7e5 100644
--- a/ext/dom/tests/modern/css_selectors/combinators.phpt
+++ b/ext/dom/tests/modern/css_selectors/combinators.phpt
@@ -56,8 +56,8 @@

 try {
     test_helper($dom, 'col.selected||td');
-} catch (ValueError $e) {
-    echo $e->getMessage(), "\n";
+} catch (Throwable $e) {
+    echo $e::class, ': ', $e->getMessage(), "\n";
 }

 ?>
@@ -110,4 +110,4 @@
 --- Selector: article[title].bar p ---
 <p xmlns="http://www.w3.org/1999/xhtml" class="bar">Fifth p</p>
 --- Selector: col.selected||td ---
-Dom\Document::querySelectorAll(): Argument #1 ($selectors) contains an unsupported selector
+ValueError: Dom\Document::querySelectorAll(): Argument #1 ($selectors) contains an unsupported selector
diff --git a/ext/dom/tests/modern/css_selectors/matches_invalid_selector.phpt b/ext/dom/tests/modern/css_selectors/matches_invalid_selector.phpt
index 11cc4a942d2..936b9d541ac 100644
--- a/ext/dom/tests/modern/css_selectors/matches_invalid_selector.phpt
+++ b/ext/dom/tests/modern/css_selectors/matches_invalid_selector.phpt
@@ -9,10 +9,10 @@

 try {
   var_dump($dom->documentElement->matches('@invalid'));
-} catch (DOMException $e) {
-  echo $e->getMessage();
+} catch (Throwable $e) {
+  echo $e::class, ': ', $e->getMessage(), "\n";
 }

 ?>
 --EXPECT--
-Invalid selector (Selectors. Unexpected token: @invalid)
+DOMException: Invalid selector (Selectors. Unexpected token: @invalid)
diff --git a/ext/dom/tests/modern/css_selectors/pseudo_classes_blank.phpt b/ext/dom/tests/modern/css_selectors/pseudo_classes_blank.phpt
index b1be7db685d..acecf6903fe 100644
--- a/ext/dom/tests/modern/css_selectors/pseudo_classes_blank.phpt
+++ b/ext/dom/tests/modern/css_selectors/pseudo_classes_blank.phpt
@@ -13,11 +13,11 @@

 try {
     test_helper($dom, ':blank');
-} catch (DOMException $e) {
-    echo $e->getMessage(), "\n";
+} catch (Throwable $e) {
+    echo $e::class, ': ', $e->getMessage(), "\n";
 }

 ?>
 --EXPECT--
 --- Selector: :blank ---
-:blank selector is not implemented because CSSWG has not yet decided its semantics (https://github.com/w3c/csswg-drafts/issues/1967)
+DOMException: :blank selector is not implemented because CSSWG has not yet decided its semantics (https://github.com/w3c/csswg-drafts/issues/1967)
diff --git a/ext/dom/tests/modern/extensions/Element_renaming_html_ns_02.phpt b/ext/dom/tests/modern/extensions/Element_renaming_html_ns_02.phpt
index 76bc6fbd0cf..9a545dd767a 100644
--- a/ext/dom/tests/modern/extensions/Element_renaming_html_ns_02.phpt
+++ b/ext/dom/tests/modern/extensions/Element_renaming_html_ns_02.phpt
@@ -9,17 +9,17 @@
 $el = $dom->createElementNS("http://www.w3.org/1999/xhtml", "foo:bar");
 try {
     $el->rename("urn:a", "foo:baz");
-} catch (DOMException $e) {
-    echo $e->getMessage(), "\n";
+} catch (Throwable $e) {
+    echo $e::class, ': ', $e->getMessage(), "\n";
 }
 $el = $dom->createElementNS("urn:a", "foo:bar");
 try {
     $el->rename("http://www.w3.org/1999/xhtml", "foo:baz");
-} catch (DOMException $e) {
-    echo $e->getMessage(), "\n";
+} catch (Throwable $e) {
+    echo $e::class, ': ', $e->getMessage(), "\n";
 }

 ?>
 --EXPECT--
-It is not possible to move an element out of the HTML namespace because the HTML namespace is tied to the HTMLElement class
-It is not possible to move an element into the HTML namespace because the HTML namespace is tied to the HTMLElement class
+DOMException: It is not possible to move an element out of the HTML namespace because the HTML namespace is tied to the HTMLElement class
+DOMException: It is not possible to move an element into the HTML namespace because the HTML namespace is tied to the HTMLElement class
diff --git a/ext/dom/tests/modern/extensions/attribute_renaming_conflict.phpt b/ext/dom/tests/modern/extensions/attribute_renaming_conflict.phpt
index a63437ebd80..4a7d5007ea4 100644
--- a/ext/dom/tests/modern/extensions/attribute_renaming_conflict.phpt
+++ b/ext/dom/tests/modern/extensions/attribute_renaming_conflict.phpt
@@ -19,38 +19,38 @@
 $root = $dom->documentElement;
 try {
     $root->attributes[0]->rename(NULL, 'c');
-} catch (DOMException $e) {
-    echo $e->getMessage(), "\n";
+} catch (Throwable $e) {
+    echo $e::class, ': ', $e->getMessage(), "\n";
 }
 try {
     $root->attributes[0]->rename(NULL, 'c');
-} catch (DOMException $e) {
-    echo $e->getMessage(), "\n";
+} catch (Throwable $e) {
+    echo $e::class, ': ', $e->getMessage(), "\n";
 }
 try {
     $root->attributes[1]->rename(NULL, 'a');
-} catch (DOMException $e) {
-    echo $e->getMessage(), "\n";
+} catch (Throwable $e) {
+    echo $e::class, ': ', $e->getMessage(), "\n";
 }
 try {
     $root->attributes[1]->rename('urn:a', 'foo');
-} catch (DOMException $e) {
-    echo $e->getMessage(), "\n";
+} catch (Throwable $e) {
+    echo $e::class, ': ', $e->getMessage(), "\n";
 }
 try {
     $root->attributes[3]->rename('', 'a');
-} catch (DOMException $e) {
-    echo $e->getMessage(), "\n";
+} catch (Throwable $e) {
+    echo $e::class, ': ', $e->getMessage(), "\n";
 }
 try {
     $root->firstElementChild->attributes[0]->rename(NULL, 'hello');
-} catch (DOMException $e) {
-    echo $e->getMessage(), "\n";
+} catch (Throwable $e) {
+    echo $e::class, ': ', $e->getMessage(), "\n";
 }
 try {
     $root->firstElementChild->attributes[1]->rename(NULL, 'my-attr');
-} catch (DOMException $e) {
-    echo $e->getMessage(), "\n";
+} catch (Throwable $e) {
+    echo $e::class, ': ', $e->getMessage(), "\n";
 }

 // This is here to validate that nothing actually changed
@@ -58,12 +58,12 @@

 ?>
 --EXPECT--
-An attribute with the given name in the given namespace already exists
-An attribute with the given name in the given namespace already exists
-An attribute with the given name in the given namespace already exists
-An attribute with the given name in the given namespace already exists
-An attribute with the given name in the given namespace already exists
-An attribute with the given name in the given namespace already exists
+DOMException: An attribute with the given name in the given namespace already exists
+DOMException: An attribute with the given name in the given namespace already exists
+DOMException: An attribute with the given name in the given namespace already exists
+DOMException: An attribute with the given name in the given namespace already exists
+DOMException: An attribute with the given name in the given namespace already exists
+DOMException: An attribute with the given name in the given namespace already exists
 <?xml version="1.0" encoding="UTF-8"?>
 <!DOCTYPE root [
 <!ELEMENT implied-attribute ANY>
diff --git a/ext/dom/tests/modern/extensions/node_renaming_validation_errors.phpt b/ext/dom/tests/modern/extensions/node_renaming_validation_errors.phpt
index 5f899c8e814..2dcd71d2554 100644
--- a/ext/dom/tests/modern/extensions/node_renaming_validation_errors.phpt
+++ b/ext/dom/tests/modern/extensions/node_renaming_validation_errors.phpt
@@ -9,21 +9,21 @@

 try {
     $dom->documentElement->rename('', 'a:b');
-} catch (DOMException $e) {
-    echo $e->getMessage(), "\n";
+} catch (Throwable $e) {
+    echo $e::class, ': ', $e->getMessage(), "\n";
 }

 try {
     $dom->documentElement->rename('urn:a', 'a:b:c');
-} catch (DOMException $e) {
-    echo $e->getMessage(), "\n";
+} catch (Throwable $e) {
+    echo $e::class, ': ', $e->getMessage(), "\n";
 }

 echo $dom->saveXML();

 ?>
 --EXPECT--
-Namespace Error
-Invalid Character Error
+DOMException: Namespace Error
+DOMException: Invalid Character Error
 <?xml version="1.0" encoding="UTF-8"?>
 <root/>
diff --git a/ext/dom/tests/modern/html/encoding/HTMLDocument_createFromFile_override_encoding.phpt b/ext/dom/tests/modern/html/encoding/HTMLDocument_createFromFile_override_encoding.phpt
index 6b87f1d4714..12115e2e16a 100644
--- a/ext/dom/tests/modern/html/encoding/HTMLDocument_createFromFile_override_encoding.phpt
+++ b/ext/dom/tests/modern/html/encoding/HTMLDocument_createFromFile_override_encoding.phpt
@@ -7,8 +7,8 @@

 try {
     Dom\HTMLDocument::createFromFile(__DIR__ . '/gb18030_without_charset.html', overrideEncoding: 'nonexistent');
-} catch (ValueError $e) {
-    echo $e->getMessage(), "\n";
+} catch (Throwable $e) {
+    echo $e::class, ': ', $e->getMessage(), "\n";
 }

 // The override encoding matches with the document encoding attribute
@@ -23,7 +23,7 @@

 ?>
 --EXPECT--
-Dom\HTMLDocument::createFromFile(): Argument #3 ($overrideEncoding) must be a valid document encoding
+ValueError: Dom\HTMLDocument::createFromFile(): Argument #3 ($overrideEncoding) must be a valid document encoding
 string(20) "
     Héllo, world!
 "
diff --git a/ext/dom/tests/modern/html/encoding/HTMLDocument_createFromString_override_encoding.phpt b/ext/dom/tests/modern/html/encoding/HTMLDocument_createFromString_override_encoding.phpt
index 75984d6acd9..43be0bcea45 100644
--- a/ext/dom/tests/modern/html/encoding/HTMLDocument_createFromString_override_encoding.phpt
+++ b/ext/dom/tests/modern/html/encoding/HTMLDocument_createFromString_override_encoding.phpt
@@ -7,8 +7,8 @@

 try {
     Dom\HTMLDocument::createFromString(file_get_contents(__DIR__ . '/gb18030_without_charset.html'), overrideEncoding: 'nonexistent');
-} catch (ValueError $e) {
-    echo $e->getMessage(), "\n";
+} catch (Throwable $e) {
+    echo $e::class, ': ', $e->getMessage(), "\n";
 }

 // The override encoding matches with the document encoding attribute
@@ -23,7 +23,7 @@

 ?>
 --EXPECT--
-Dom\HTMLDocument::createFromString(): Argument #3 ($overrideEncoding) must be a valid document encoding
+ValueError: Dom\HTMLDocument::createFromString(): Argument #3 ($overrideEncoding) must be a valid document encoding
 string(20) "
     Héllo, world!
 "
diff --git a/ext/dom/tests/modern/html/encoding/HTMLDocument_encoding_field_test.phpt b/ext/dom/tests/modern/html/encoding/HTMLDocument_encoding_field_test.phpt
index c4417d80410..b2869676c7a 100644
--- a/ext/dom/tests/modern/html/encoding/HTMLDocument_encoding_field_test.phpt
+++ b/ext/dom/tests/modern/html/encoding/HTMLDocument_encoding_field_test.phpt
@@ -11,33 +11,33 @@
 var_dump($dom->characterSet);
 try {
     $dom->charset = "nope";
-} catch (ValueError $e) {
-    echo $e->getMessage(), "\n";
+} catch (Throwable $e) {
+    echo $e::class, ': ', $e->getMessage(), "\n";
 }
 var_dump($dom->charset);
 $dom->inputEncoding = "Windows-1251";
 var_dump($dom->characterSet);
 try {
     $dom->charset = "";
-} catch (ValueError $e) {
-    echo $e->getMessage(), "\n";
+} catch (Throwable $e) {
+    echo $e::class, ': ', $e->getMessage(), "\n";
 }
 var_dump($dom->inputEncoding);
 echo $dom->saveHtml();

 try {
     $dom = Dom\HTMLDocument::createEmpty("bogus");
-} catch (ValueError $e) {
-    echo $e->getMessage(), "\n";
+} catch (Throwable $e) {
+    echo $e::class, ': ', $e->getMessage(), "\n";
 }

 ?>
 --EXPECT--
 string(5) "UTF-8"
 string(6) "EUC-KR"
-Invalid document encoding
+ValueError: Invalid document encoding
 string(6) "EUC-KR"
 string(12) "windows-1251"
-Invalid document encoding
+ValueError: Invalid document encoding
 string(12) "windows-1251"
-Dom\HTMLDocument::createEmpty(): Argument #1 ($encoding) must be a valid document encoding
+ValueError: Dom\HTMLDocument::createEmpty(): Argument #1 ($encoding) must be a valid document encoding
diff --git a/ext/dom/tests/modern/html/interactions/Document_body_setter_errors.phpt b/ext/dom/tests/modern/html/interactions/Document_body_setter_errors.phpt
index 1f934fcff89..b978eddf1da 100644
--- a/ext/dom/tests/modern/html/interactions/Document_body_setter_errors.phpt
+++ b/ext/dom/tests/modern/html/interactions/Document_body_setter_errors.phpt
@@ -12,7 +12,7 @@ function testNormalReplace($cb)
     try {
         $dom->body = $cb($dom);
     } catch (Throwable $e) {
-        echo $e->getMessage(), "\n";
+        echo $e::class, ': ', $e->getMessage(), "\n";
     }
     var_dump($dom->body?->nodeName);
 }
@@ -33,8 +33,8 @@ function testNormalReplace($cb)
 $dom = DOM\XMLDocument::createEmpty();
 try {
     $dom->body = $dom->createElementNS("http://www.w3.org/1999/xhtml", "body");
-} catch (DOMException $e) {
-    echo $e->getMessage(), "\n";
+} catch (Throwable $e) {
+    echo $e::class, ': ', $e->getMessage(), "\n";
 }
 var_dump($dom->body?->nodeName);

@@ -42,20 +42,20 @@ function testNormalReplace($cb)
 --EXPECT--
 --- Set body to NULL ---
 string(4) "BODY"
-The new body must either be a body or a frameset tag
+DOMException: The new body must either be a body or a frameset tag
 string(4) "BODY"
 --- Wrong element tag in right namespace ---
 string(4) "BODY"
-The new body must either be a body or a frameset tag
+DOMException: The new body must either be a body or a frameset tag
 string(4) "BODY"
 --- Right element tag in wrong namespace ---
 string(4) "BODY"
-Cannot assign Dom\Element to property Dom\Document::$body of type ?Dom\HTMLElement
+TypeError: Cannot assign Dom\Element to property Dom\Document::$body of type ?Dom\HTMLElement
 string(4) "BODY"
 --- Right element tag in no namespace ---
 string(4) "BODY"
-Cannot assign Dom\Element to property Dom\Document::$body of type ?Dom\HTMLElement
+TypeError: Cannot assign Dom\Element to property Dom\Document::$body of type ?Dom\HTMLElement
 string(4) "BODY"
 --- Set body without document element ---
-A body can only be set if there is a document element
+DOMException: A body can only be set if there is a document element
 NULL
diff --git a/ext/dom/tests/modern/html/interactions/Dom_Element_insertAdjacentHTML_errors.phpt b/ext/dom/tests/modern/html/interactions/Dom_Element_insertAdjacentHTML_errors.phpt
index b8e13ba436b..a0b03df695c 100644
--- a/ext/dom/tests/modern/html/interactions/Dom_Element_insertAdjacentHTML_errors.phpt
+++ b/ext/dom/tests/modern/html/interactions/Dom_Element_insertAdjacentHTML_errors.phpt
@@ -12,16 +12,16 @@

 try {
     $element->insertAdjacentHTML(Dom\AdjacentPosition::BeforeBegin, "test");
-} catch (DOMException $e) {
-    echo $e->getMessage(), "\n";
+} catch (Throwable $e) {
+    echo $e::class, ': ', $e->getMessage(), "\n";
 }

 echo "--- AfterEnd no parent ---\n";

 try {
     $element->insertAdjacentHTML(Dom\AdjacentPosition::AfterEnd, "test");
-} catch (DOMException $e) {
-    echo $e->getMessage(), "\n";
+} catch (Throwable $e) {
+    echo $e::class, ': ', $e->getMessage(), "\n";
 }

 $dom->appendChild($element);
@@ -30,25 +30,25 @@

 try {
     $element->insertAdjacentHTML(Dom\AdjacentPosition::BeforeBegin, "test");
-} catch (DOMException $e) {
-    echo $e->getMessage(), "\n";
+} catch (Throwable $e) {
+    echo $e::class, ': ', $e->getMessage(), "\n";
 }

 echo "--- AfterEnd document parent ---\n";

 try {
     $element->insertAdjacentHTML(Dom\AdjacentPosition::AfterEnd, "test");
-} catch (DOMException $e) {
-    echo $e->getMessage(), "\n";
+} catch (Throwable $e) {
+    echo $e::class, ': ', $e->getMessage(), "\n";
 }

 ?>
 --EXPECT--
 --- BeforeBegin no parent ---
-No Modification Allowed Error
+DOMException: No Modification Allowed Error
 --- AfterEnd no parent ---
-No Modification Allowed Error
+DOMException: No Modification Allowed Error
 --- BeforeBegin document parent ---
-No Modification Allowed Error
+DOMException: No Modification Allowed Error
 --- AfterEnd document parent ---
-No Modification Allowed Error
+DOMException: No Modification Allowed Error
diff --git a/ext/dom/tests/modern/html/interactions/HTMLCollection_dimension_errors.phpt b/ext/dom/tests/modern/html/interactions/HTMLCollection_dimension_errors.phpt
index 571f94e4d34..1554e9e582f 100644
--- a/ext/dom/tests/modern/html/interactions/HTMLCollection_dimension_errors.phpt
+++ b/ext/dom/tests/modern/html/interactions/HTMLCollection_dimension_errors.phpt
@@ -9,24 +9,24 @@

 try {
     $dom->getElementsByTagName('root')[][1] = 1;
-} catch (Error $e) {
-    echo $e->getMessage(), "\n";
+} catch (Throwable $e) {
+    echo $e::class, ': ', $e->getMessage(), "\n";
 }

 try {
     $dom->getElementsByTagName('root')[true];
-} catch (Error $e) {
-    echo $e->getMessage(), "\n";
+} catch (Throwable $e) {
+    echo $e::class, ': ', $e->getMessage(), "\n";
 }

 try {
     isset($dom->getElementsByTagName('root')[true]);
-} catch (Error $e) {
-    echo $e->getMessage(), "\n";
+} catch (Throwable $e) {
+    echo $e::class, ': ', $e->getMessage(), "\n";
 }

 ?>
 --EXPECT--
-Cannot append to Dom\HTMLCollection
-Cannot access offset of type bool on Dom\HTMLCollection
-Cannot access offset of type bool in isset or empty
+Error: Cannot append to Dom\HTMLCollection
+TypeError: Cannot access offset of type bool on Dom\HTMLCollection
+TypeError: Cannot access offset of type bool in isset or empty
diff --git a/ext/dom/tests/modern/html/interactions/HTMLDocument_registerNodeClass_02.phpt b/ext/dom/tests/modern/html/interactions/HTMLDocument_registerNodeClass_02.phpt
index 70be58a906b..04eceb44345 100644
--- a/ext/dom/tests/modern/html/interactions/HTMLDocument_registerNodeClass_02.phpt
+++ b/ext/dom/tests/modern/html/interactions/HTMLDocument_registerNodeClass_02.phpt
@@ -13,8 +13,8 @@ public function foo() {
 $dom = Dom\HTMLDocument::createEmpty();
 try {
     $dom->registerNodeClass("Dom\\Document", "Custom");
-} catch (ValueError $e) {
-    echo $e->getMessage(), "\n";
+} catch (Throwable $e) {
+    echo $e::class, ': ', $e->getMessage(), "\n";
 }

 $element = $dom->appendChild($dom->createElement("foo"));
@@ -27,7 +27,7 @@ public function foo() {

 ?>
 --EXPECTF--
-Dom\Document::registerNodeClass(): Argument #1 ($baseClass) must not be an abstract class
+ValueError: Dom\Document::registerNodeClass(): Argument #1 ($baseClass) must not be an abstract class
 string(16) "Dom\HTMLDocument"

 Fatal error: Uncaught Error: Call to undefined method Dom\HTMLDocument::foo() in %s:%d
diff --git a/ext/dom/tests/modern/html/interactions/without_constructor.phpt b/ext/dom/tests/modern/html/interactions/without_constructor.phpt
index 96cd131b039..be491c66fbb 100644
--- a/ext/dom/tests/modern/html/interactions/without_constructor.phpt
+++ b/ext/dom/tests/modern/html/interactions/without_constructor.phpt
@@ -9,12 +9,12 @@
     try {
         $rc = new ReflectionClass($class);
         $rc->newInstanceWithoutConstructor();
-    } catch (ReflectionException $e) {
-        echo $e->getMessage(), "\n";
+    } catch (Throwable $e) {
+        echo $e::class, ': ', $e->getMessage(), "\n";
     }
 }

 ?>
 --EXPECT--
-Class Dom\HTMLDocument is an internal class marked as final that cannot be instantiated without invoking its constructor
-Class Dom\XMLDocument is an internal class marked as final that cannot be instantiated without invoking its constructor
+ReflectionException: Class Dom\HTMLDocument is an internal class marked as final that cannot be instantiated without invoking its constructor
+ReflectionException: Class Dom\XMLDocument is an internal class marked as final that cannot be instantiated without invoking its constructor
diff --git a/ext/dom/tests/modern/html/parser/HTMLDocument_fromFile_nul_terminator_cases_path.phpt b/ext/dom/tests/modern/html/parser/HTMLDocument_fromFile_nul_terminator_cases_path.phpt
index 37cf161ec04..398a927ad17 100644
--- a/ext/dom/tests/modern/html/parser/HTMLDocument_fromFile_nul_terminator_cases_path.phpt
+++ b/ext/dom/tests/modern/html/parser/HTMLDocument_fromFile_nul_terminator_cases_path.phpt
@@ -7,16 +7,16 @@

 try {
     Dom\HTMLDocument::createFromFile("\0");
-} catch (ValueError $e) {
-    echo $e->getMessage(), "\n";
+} catch (Throwable $e) {
+    echo $e::class, ': ', $e->getMessage(), "\n";
 }
 try {
     Dom\HTMLDocument::createFromFile('%00');
-} catch (ValueError $e) {
-    echo $e->getMessage(), "\n";
+} catch (Throwable $e) {
+    echo $e::class, ': ', $e->getMessage(), "\n";
 }

 ?>
 --EXPECT--
-Dom\HTMLDocument::createFromFile(): Argument #1 ($path) must not contain any null bytes
-Dom\HTMLDocument::createFromFile(): Argument #1 ($path) must not contain percent-encoded NUL bytes
+ValueError: Dom\HTMLDocument::createFromFile(): Argument #1 ($path) must not contain any null bytes
+ValueError: Dom\HTMLDocument::createFromFile(): Argument #1 ($path) must not contain percent-encoded NUL bytes
diff --git a/ext/dom/tests/modern/html/parser/HTMLDocument_parse_options.phpt b/ext/dom/tests/modern/html/parser/HTMLDocument_parse_options.phpt
index f61ef2dec86..f3f00b58171 100644
--- a/ext/dom/tests/modern/html/parser/HTMLDocument_parse_options.phpt
+++ b/ext/dom/tests/modern/html/parser/HTMLDocument_parse_options.phpt
@@ -31,8 +31,8 @@
         var_dump($options);
         try {
             Dom\HTMLDocument::{$method}("x", $options);
-        } catch (ValueError $e) {
-            echo $e->getMessage(), "\n";
+        } catch (Throwable $e) {
+            echo $e::class, ': ', $e->getMessage(), "\n";
         }
     }
 }
@@ -41,67 +41,67 @@
 --EXPECTF--
 --- Method createFromString ---
 int(%d)
-Dom\HTMLDocument::createFromString(): Argument #2 ($options) contains invalid flags (allowed flags: LIBXML_NOERROR, LIBXML_COMPACT, LIBXML_HTML_NOIMPLIED, Dom\HTML_NO_DEFAULT_NS)
+ValueError: Dom\HTMLDocument::createFromString(): Argument #2 ($options) contains invalid flags (allowed flags: LIBXML_NOERROR, LIBXML_COMPACT, LIBXML_HTML_NOIMPLIED, Dom\HTML_NO_DEFAULT_NS)
 int(4194304)
-Dom\HTMLDocument::createFromString(): Argument #2 ($options) contains invalid flags (allowed flags: LIBXML_NOERROR, LIBXML_COMPACT, LIBXML_HTML_NOIMPLIED, Dom\HTML_NO_DEFAULT_NS)
+ValueError: Dom\HTMLDocument::createFromString(): Argument #2 ($options) contains invalid flags (allowed flags: LIBXML_NOERROR, LIBXML_COMPACT, LIBXML_HTML_NOIMPLIED, Dom\HTML_NO_DEFAULT_NS)
 int(524288)
-Dom\HTMLDocument::createFromString(): Argument #2 ($options) contains invalid flags (allowed flags: LIBXML_NOERROR, LIBXML_COMPACT, LIBXML_HTML_NOIMPLIED, Dom\HTML_NO_DEFAULT_NS)
+ValueError: Dom\HTMLDocument::createFromString(): Argument #2 ($options) contains invalid flags (allowed flags: LIBXML_NOERROR, LIBXML_COMPACT, LIBXML_HTML_NOIMPLIED, Dom\HTML_NO_DEFAULT_NS)
 int(8)
-Dom\HTMLDocument::createFromString(): Argument #2 ($options) contains invalid flags (allowed flags: LIBXML_NOERROR, LIBXML_COMPACT, LIBXML_HTML_NOIMPLIED, Dom\HTML_NO_DEFAULT_NS)
+ValueError: Dom\HTMLDocument::createFromString(): Argument #2 ($options) contains invalid flags (allowed flags: LIBXML_NOERROR, LIBXML_COMPACT, LIBXML_HTML_NOIMPLIED, Dom\HTML_NO_DEFAULT_NS)
 int(4)
-Dom\HTMLDocument::createFromString(): Argument #2 ($options) contains invalid flags (allowed flags: LIBXML_NOERROR, LIBXML_COMPACT, LIBXML_HTML_NOIMPLIED, Dom\HTML_NO_DEFAULT_NS)
+ValueError: Dom\HTMLDocument::createFromString(): Argument #2 ($options) contains invalid flags (allowed flags: LIBXML_NOERROR, LIBXML_COMPACT, LIBXML_HTML_NOIMPLIED, Dom\HTML_NO_DEFAULT_NS)
 int(16)
-Dom\HTMLDocument::createFromString(): Argument #2 ($options) contains invalid flags (allowed flags: LIBXML_NOERROR, LIBXML_COMPACT, LIBXML_HTML_NOIMPLIED, Dom\HTML_NO_DEFAULT_NS)
+ValueError: Dom\HTMLDocument::createFromString(): Argument #2 ($options) contains invalid flags (allowed flags: LIBXML_NOERROR, LIBXML_COMPACT, LIBXML_HTML_NOIMPLIED, Dom\HTML_NO_DEFAULT_NS)
 int(4)
-Dom\HTMLDocument::createFromString(): Argument #2 ($options) contains invalid flags (allowed flags: LIBXML_NOERROR, LIBXML_COMPACT, LIBXML_HTML_NOIMPLIED, Dom\HTML_NO_DEFAULT_NS)
+ValueError: Dom\HTMLDocument::createFromString(): Argument #2 ($options) contains invalid flags (allowed flags: LIBXML_NOERROR, LIBXML_COMPACT, LIBXML_HTML_NOIMPLIED, Dom\HTML_NO_DEFAULT_NS)
 int(256)
-Dom\HTMLDocument::createFromString(): Argument #2 ($options) contains invalid flags (allowed flags: LIBXML_NOERROR, LIBXML_COMPACT, LIBXML_HTML_NOIMPLIED, Dom\HTML_NO_DEFAULT_NS)
+ValueError: Dom\HTMLDocument::createFromString(): Argument #2 ($options) contains invalid flags (allowed flags: LIBXML_NOERROR, LIBXML_COMPACT, LIBXML_HTML_NOIMPLIED, Dom\HTML_NO_DEFAULT_NS)
 int(16384)
-Dom\HTMLDocument::createFromString(): Argument #2 ($options) contains invalid flags (allowed flags: LIBXML_NOERROR, LIBXML_COMPACT, LIBXML_HTML_NOIMPLIED, Dom\HTML_NO_DEFAULT_NS)
+ValueError: Dom\HTMLDocument::createFromString(): Argument #2 ($options) contains invalid flags (allowed flags: LIBXML_NOERROR, LIBXML_COMPACT, LIBXML_HTML_NOIMPLIED, Dom\HTML_NO_DEFAULT_NS)
 int(4)
-Dom\HTMLDocument::createFromString(): Argument #2 ($options) contains invalid flags (allowed flags: LIBXML_NOERROR, LIBXML_COMPACT, LIBXML_HTML_NOIMPLIED, Dom\HTML_NO_DEFAULT_NS)
+ValueError: Dom\HTMLDocument::createFromString(): Argument #2 ($options) contains invalid flags (allowed flags: LIBXML_NOERROR, LIBXML_COMPACT, LIBXML_HTML_NOIMPLIED, Dom\HTML_NO_DEFAULT_NS)
 int(2)
-Dom\HTMLDocument::createFromString(): Argument #2 ($options) contains invalid flags (allowed flags: LIBXML_NOERROR, LIBXML_COMPACT, LIBXML_HTML_NOIMPLIED, Dom\HTML_NO_DEFAULT_NS)
+ValueError: Dom\HTMLDocument::createFromString(): Argument #2 ($options) contains invalid flags (allowed flags: LIBXML_NOERROR, LIBXML_COMPACT, LIBXML_HTML_NOIMPLIED, Dom\HTML_NO_DEFAULT_NS)
 int(1024)
-Dom\HTMLDocument::createFromString(): Argument #2 ($options) contains invalid flags (allowed flags: LIBXML_NOERROR, LIBXML_COMPACT, LIBXML_HTML_NOIMPLIED, Dom\HTML_NO_DEFAULT_NS)
+ValueError: Dom\HTMLDocument::createFromString(): Argument #2 ($options) contains invalid flags (allowed flags: LIBXML_NOERROR, LIBXML_COMPACT, LIBXML_HTML_NOIMPLIED, Dom\HTML_NO_DEFAULT_NS)
 int(1)
-Dom\HTMLDocument::createFromString(): Argument #2 ($options) contains invalid flags (allowed flags: LIBXML_NOERROR, LIBXML_COMPACT, LIBXML_HTML_NOIMPLIED, Dom\HTML_NO_DEFAULT_NS)
+ValueError: Dom\HTMLDocument::createFromString(): Argument #2 ($options) contains invalid flags (allowed flags: LIBXML_NOERROR, LIBXML_COMPACT, LIBXML_HTML_NOIMPLIED, Dom\HTML_NO_DEFAULT_NS)
 int(2048)
-Dom\HTMLDocument::createFromString(): Argument #2 ($options) contains invalid flags (allowed flags: LIBXML_NOERROR, LIBXML_COMPACT, LIBXML_HTML_NOIMPLIED, Dom\HTML_NO_DEFAULT_NS)
+ValueError: Dom\HTMLDocument::createFromString(): Argument #2 ($options) contains invalid flags (allowed flags: LIBXML_NOERROR, LIBXML_COMPACT, LIBXML_HTML_NOIMPLIED, Dom\HTML_NO_DEFAULT_NS)
 int(64)
-Dom\HTMLDocument::createFromString(): Argument #2 ($options) contains invalid flags (allowed flags: LIBXML_NOERROR, LIBXML_COMPACT, LIBXML_HTML_NOIMPLIED, Dom\HTML_NO_DEFAULT_NS)
+ValueError: Dom\HTMLDocument::createFromString(): Argument #2 ($options) contains invalid flags (allowed flags: LIBXML_NOERROR, LIBXML_COMPACT, LIBXML_HTML_NOIMPLIED, Dom\HTML_NO_DEFAULT_NS)
 int(128)
-Dom\HTMLDocument::createFromString(): Argument #2 ($options) contains invalid flags (allowed flags: LIBXML_NOERROR, LIBXML_COMPACT, LIBXML_HTML_NOIMPLIED, Dom\HTML_NO_DEFAULT_NS)
+ValueError: Dom\HTMLDocument::createFromString(): Argument #2 ($options) contains invalid flags (allowed flags: LIBXML_NOERROR, LIBXML_COMPACT, LIBXML_HTML_NOIMPLIED, Dom\HTML_NO_DEFAULT_NS)
 --- Method createFromFile ---
 int(%d)
-Dom\HTMLDocument::createFromFile(): Argument #2 ($options) contains invalid flags (allowed flags: LIBXML_NOERROR, LIBXML_COMPACT, LIBXML_HTML_NOIMPLIED, Dom\HTML_NO_DEFAULT_NS)
+ValueError: Dom\HTMLDocument::createFromFile(): Argument #2 ($options) contains invalid flags (allowed flags: LIBXML_NOERROR, LIBXML_COMPACT, LIBXML_HTML_NOIMPLIED, Dom\HTML_NO_DEFAULT_NS)
 int(4194304)
-Dom\HTMLDocument::createFromFile(): Argument #2 ($options) contains invalid flags (allowed flags: LIBXML_NOERROR, LIBXML_COMPACT, LIBXML_HTML_NOIMPLIED, Dom\HTML_NO_DEFAULT_NS)
+ValueError: Dom\HTMLDocument::createFromFile(): Argument #2 ($options) contains invalid flags (allowed flags: LIBXML_NOERROR, LIBXML_COMPACT, LIBXML_HTML_NOIMPLIED, Dom\HTML_NO_DEFAULT_NS)
 int(524288)
-Dom\HTMLDocument::createFromFile(): Argument #2 ($options) contains invalid flags (allowed flags: LIBXML_NOERROR, LIBXML_COMPACT, LIBXML_HTML_NOIMPLIED, Dom\HTML_NO_DEFAULT_NS)
+ValueError: Dom\HTMLDocument::createFromFile(): Argument #2 ($options) contains invalid flags (allowed flags: LIBXML_NOERROR, LIBXML_COMPACT, LIBXML_HTML_NOIMPLIED, Dom\HTML_NO_DEFAULT_NS)
 int(8)
-Dom\HTMLDocument::createFromFile(): Argument #2 ($options) contains invalid flags (allowed flags: LIBXML_NOERROR, LIBXML_COMPACT, LIBXML_HTML_NOIMPLIED, Dom\HTML_NO_DEFAULT_NS)
+ValueError: Dom\HTMLDocument::createFromFile(): Argument #2 ($options) contains invalid flags (allowed flags: LIBXML_NOERROR, LIBXML_COMPACT, LIBXML_HTML_NOIMPLIED, Dom\HTML_NO_DEFAULT_NS)
 int(4)
-Dom\HTMLDocument::createFromFile(): Argument #2 ($options) contains invalid flags (allowed flags: LIBXML_NOERROR, LIBXML_COMPACT, LIBXML_HTML_NOIMPLIED, Dom\HTML_NO_DEFAULT_NS)
+ValueError: Dom\HTMLDocument::createFromFile(): Argument #2 ($options) contains invalid flags (allowed flags: LIBXML_NOERROR, LIBXML_COMPACT, LIBXML_HTML_NOIMPLIED, Dom\HTML_NO_DEFAULT_NS)
 int(16)
-Dom\HTMLDocument::createFromFile(): Argument #2 ($options) contains invalid flags (allowed flags: LIBXML_NOERROR, LIBXML_COMPACT, LIBXML_HTML_NOIMPLIED, Dom\HTML_NO_DEFAULT_NS)
+ValueError: Dom\HTMLDocument::createFromFile(): Argument #2 ($options) contains invalid flags (allowed flags: LIBXML_NOERROR, LIBXML_COMPACT, LIBXML_HTML_NOIMPLIED, Dom\HTML_NO_DEFAULT_NS)
 int(4)
-Dom\HTMLDocument::createFromFile(): Argument #2 ($options) contains invalid flags (allowed flags: LIBXML_NOERROR, LIBXML_COMPACT, LIBXML_HTML_NOIMPLIED, Dom\HTML_NO_DEFAULT_NS)
+ValueError: Dom\HTMLDocument::createFromFile(): Argument #2 ($options) contains invalid flags (allowed flags: LIBXML_NOERROR, LIBXML_COMPACT, LIBXML_HTML_NOIMPLIED, Dom\HTML_NO_DEFAULT_NS)
 int(256)
-Dom\HTMLDocument::createFromFile(): Argument #2 ($options) contains invalid flags (allowed flags: LIBXML_NOERROR, LIBXML_COMPACT, LIBXML_HTML_NOIMPLIED, Dom\HTML_NO_DEFAULT_NS)
+ValueError: Dom\HTMLDocument::createFromFile(): Argument #2 ($options) contains invalid flags (allowed flags: LIBXML_NOERROR, LIBXML_COMPACT, LIBXML_HTML_NOIMPLIED, Dom\HTML_NO_DEFAULT_NS)
 int(16384)
-Dom\HTMLDocument::createFromFile(): Argument #2 ($options) contains invalid flags (allowed flags: LIBXML_NOERROR, LIBXML_COMPACT, LIBXML_HTML_NOIMPLIED, Dom\HTML_NO_DEFAULT_NS)
+ValueError: Dom\HTMLDocument::createFromFile(): Argument #2 ($options) contains invalid flags (allowed flags: LIBXML_NOERROR, LIBXML_COMPACT, LIBXML_HTML_NOIMPLIED, Dom\HTML_NO_DEFAULT_NS)
 int(4)
-Dom\HTMLDocument::createFromFile(): Argument #2 ($options) contains invalid flags (allowed flags: LIBXML_NOERROR, LIBXML_COMPACT, LIBXML_HTML_NOIMPLIED, Dom\HTML_NO_DEFAULT_NS)
+ValueError: Dom\HTMLDocument::createFromFile(): Argument #2 ($options) contains invalid flags (allowed flags: LIBXML_NOERROR, LIBXML_COMPACT, LIBXML_HTML_NOIMPLIED, Dom\HTML_NO_DEFAULT_NS)
 int(2)
-Dom\HTMLDocument::createFromFile(): Argument #2 ($options) contains invalid flags (allowed flags: LIBXML_NOERROR, LIBXML_COMPACT, LIBXML_HTML_NOIMPLIED, Dom\HTML_NO_DEFAULT_NS)
+ValueError: Dom\HTMLDocument::createFromFile(): Argument #2 ($options) contains invalid flags (allowed flags: LIBXML_NOERROR, LIBXML_COMPACT, LIBXML_HTML_NOIMPLIED, Dom\HTML_NO_DEFAULT_NS)
 int(1024)
-Dom\HTMLDocument::createFromFile(): Argument #2 ($options) contains invalid flags (allowed flags: LIBXML_NOERROR, LIBXML_COMPACT, LIBXML_HTML_NOIMPLIED, Dom\HTML_NO_DEFAULT_NS)
+ValueError: Dom\HTMLDocument::createFromFile(): Argument #2 ($options) contains invalid flags (allowed flags: LIBXML_NOERROR, LIBXML_COMPACT, LIBXML_HTML_NOIMPLIED, Dom\HTML_NO_DEFAULT_NS)
 int(1)
-Dom\HTMLDocument::createFromFile(): Argument #2 ($options) contains invalid flags (allowed flags: LIBXML_NOERROR, LIBXML_COMPACT, LIBXML_HTML_NOIMPLIED, Dom\HTML_NO_DEFAULT_NS)
+ValueError: Dom\HTMLDocument::createFromFile(): Argument #2 ($options) contains invalid flags (allowed flags: LIBXML_NOERROR, LIBXML_COMPACT, LIBXML_HTML_NOIMPLIED, Dom\HTML_NO_DEFAULT_NS)
 int(2048)
-Dom\HTMLDocument::createFromFile(): Argument #2 ($options) contains invalid flags (allowed flags: LIBXML_NOERROR, LIBXML_COMPACT, LIBXML_HTML_NOIMPLIED, Dom\HTML_NO_DEFAULT_NS)
+ValueError: Dom\HTMLDocument::createFromFile(): Argument #2 ($options) contains invalid flags (allowed flags: LIBXML_NOERROR, LIBXML_COMPACT, LIBXML_HTML_NOIMPLIED, Dom\HTML_NO_DEFAULT_NS)
 int(64)
-Dom\HTMLDocument::createFromFile(): Argument #2 ($options) contains invalid flags (allowed flags: LIBXML_NOERROR, LIBXML_COMPACT, LIBXML_HTML_NOIMPLIED, Dom\HTML_NO_DEFAULT_NS)
+ValueError: Dom\HTMLDocument::createFromFile(): Argument #2 ($options) contains invalid flags (allowed flags: LIBXML_NOERROR, LIBXML_COMPACT, LIBXML_HTML_NOIMPLIED, Dom\HTML_NO_DEFAULT_NS)
 int(128)
-Dom\HTMLDocument::createFromFile(): Argument #2 ($options) contains invalid flags (allowed flags: LIBXML_NOERROR, LIBXML_COMPACT, LIBXML_HTML_NOIMPLIED, Dom\HTML_NO_DEFAULT_NS)
+ValueError: Dom\HTMLDocument::createFromFile(): Argument #2 ($options) contains invalid flags (allowed flags: LIBXML_NOERROR, LIBXML_COMPACT, LIBXML_HTML_NOIMPLIED, Dom\HTML_NO_DEFAULT_NS)
diff --git a/ext/dom/tests/modern/spec/CharacterData_deleteData_negative_in_bounds_length.phpt b/ext/dom/tests/modern/spec/CharacterData_deleteData_negative_in_bounds_length.phpt
index f29a201ca10..0cefe145ead 100644
--- a/ext/dom/tests/modern/spec/CharacterData_deleteData_negative_in_bounds_length.phpt
+++ b/ext/dom/tests/modern/spec/CharacterData_deleteData_negative_in_bounds_length.phpt
@@ -18,8 +18,8 @@
 $comment = $dom->createComment("foobarbaz");
 try {
     $comment->deleteData(3, -1);
-} catch (DOMException $e) {
-    echo $e->getMessage(), "\n";
+} catch (Throwable $e) {
+    echo $e::class, ': ', $e->getMessage(), "\n";
 }
 echo $dom->saveHtml($comment), "\n";

@@ -28,5 +28,5 @@
 --- Modern behaviour ---
 <!--foo-->
 --- Legacy behaviour ---
-Index Size Error
+DOMException: Index Size Error
 <!--foobarbaz-->
diff --git a/ext/dom/tests/modern/spec/CharacterData_insertData_edge_cases.phpt b/ext/dom/tests/modern/spec/CharacterData_insertData_edge_cases.phpt
index 9369bdadbff..1aaf24a8969 100644
--- a/ext/dom/tests/modern/spec/CharacterData_insertData_edge_cases.phpt
+++ b/ext/dom/tests/modern/spec/CharacterData_insertData_edge_cases.phpt
@@ -11,18 +11,18 @@
 $comment = $dom->createComment("foobarbaz");
 try {
     var_dump($comment->insertData(100, "data"));
-} catch (DOMException $e) {
-    echo $e->getMessage(), "\n";
+} catch (Throwable $e) {
+    echo $e::class, ': ', $e->getMessage(), "\n";
 }
 try {
     var_dump($comment->insertData(2**31+1, "data"));
-} catch (DOMException $e) {
-    echo $e->getMessage(), "\n";
+} catch (Throwable $e) {
+    echo $e::class, ': ', $e->getMessage(), "\n";
 }
 echo $dom->saveHtml($comment), "\n";

 ?>
 --EXPECT--
-Index Size Error
-Index Size Error
+DOMException: Index Size Error
+DOMException: Index Size Error
 <!--foobarbaz-->
diff --git a/ext/dom/tests/modern/spec/CharacterData_insertData_negative_offset.phpt b/ext/dom/tests/modern/spec/CharacterData_insertData_negative_offset.phpt
index f00e9aa76aa..c024c876dc7 100644
--- a/ext/dom/tests/modern/spec/CharacterData_insertData_negative_offset.phpt
+++ b/ext/dom/tests/modern/spec/CharacterData_insertData_negative_offset.phpt
@@ -9,8 +9,8 @@
 $comment = $dom->createComment("foobarbaz");
 try {
     $comment->insertData(-1, "A");
-} catch (DOMException $e) {
-    echo $e->getMessage(), "\n";
+} catch (Throwable $e) {
+    echo $e::class, ': ', $e->getMessage(), "\n";
 }
 echo $dom->saveHtml($comment), "\n";
 $comment->insertData(1, "A");
@@ -18,6 +18,6 @@

 ?>
 --EXPECT--
-Index Size Error
+DOMException: Index Size Error
 <!--foobarbaz-->
 <!--fAoobarbaz-->
diff --git a/ext/dom/tests/modern/spec/CharacterData_insertData_negative_offset_mod32.phpt b/ext/dom/tests/modern/spec/CharacterData_insertData_negative_offset_mod32.phpt
index 7c27c3bc8dd..c2feefd45ab 100644
--- a/ext/dom/tests/modern/spec/CharacterData_insertData_negative_offset_mod32.phpt
+++ b/ext/dom/tests/modern/spec/CharacterData_insertData_negative_offset_mod32.phpt
@@ -15,8 +15,8 @@
 $comment = $dom->createComment("foobarbaz");
 try {
     $comment->insertData(-1, "A");
-} catch (DOMException $e) {
-    echo $e->getMessage(), "\n";
+} catch (Throwable $e) {
+    echo $e::class, ': ', $e->getMessage(), "\n";
 }
 echo $dom->saveHtml($comment), "\n";
 $comment->insertData(-(2**32 - 1), "A");
@@ -28,25 +28,25 @@
 $comment = $dom->createComment("foobarbaz");
 try {
     $comment->insertData(-1, "A");
-} catch (DOMException $e) {
-    echo $e->getMessage(), "\n";
+} catch (Throwable $e) {
+    echo $e::class, ': ', $e->getMessage(), "\n";
 }
 echo $dom->saveHtml($comment), "\n";
 try {
     $comment->insertData(-(2**32 - 1), "A");
-} catch (DOMException $e) {
-    echo $e->getMessage(), "\n";
+} catch (Throwable $e) {
+    echo $e::class, ': ', $e->getMessage(), "\n";
 }
 echo $dom->saveHtml($comment), "\n";

 ?>
 --EXPECT--
 --- Modern behaviour ---
-Index Size Error
+DOMException: Index Size Error
 <!--foobarbaz-->
 <!--fAoobarbaz-->
 --- Legacy behaviour ---
-Index Size Error
+DOMException: Index Size Error
 <!--foobarbaz-->
-Index Size Error
+DOMException: Index Size Error
 <!--foobarbaz-->
diff --git a/ext/dom/tests/modern/spec/CharacterData_replaceData_negative_count_mod32.phpt b/ext/dom/tests/modern/spec/CharacterData_replaceData_negative_count_mod32.phpt
index 64634b09925..a85587c7d26 100644
--- a/ext/dom/tests/modern/spec/CharacterData_replaceData_negative_count_mod32.phpt
+++ b/ext/dom/tests/modern/spec/CharacterData_replaceData_negative_count_mod32.phpt
@@ -25,14 +25,14 @@
 $comment = $dom->createComment("foobarbaz");
 try {
     $comment->replaceData(0, -1, "A");
-} catch (DOMException $e) {
-    echo $e->getMessage(), "\n";
+} catch (Throwable $e) {
+    echo $e::class, ': ', $e->getMessage(), "\n";
 }
 echo $dom->saveHtml($comment), "\n";
 try {
     $comment->replaceData(2, -(2**32 - 2), "A");
-} catch (DOMException $e) {
-    echo $e->getMessage(), "\n";
+} catch (Throwable $e) {
+    echo $e::class, ': ', $e->getMessage(), "\n";
 }
 echo $dom->saveHtml($comment), "\n";

@@ -42,7 +42,7 @@
 <!--A-->
 <!--foAarbaz-->
 --- Legacy behaviour ---
-Index Size Error
+DOMException: Index Size Error
 <!--foobarbaz-->
-Index Size Error
+DOMException: Index Size Error
 <!--foobarbaz-->
diff --git a/ext/dom/tests/modern/spec/CharacterData_substringData_edge_cases.phpt b/ext/dom/tests/modern/spec/CharacterData_substringData_edge_cases.phpt
index c463c0f7057..e7f81f765db 100644
--- a/ext/dom/tests/modern/spec/CharacterData_substringData_edge_cases.phpt
+++ b/ext/dom/tests/modern/spec/CharacterData_substringData_edge_cases.phpt
@@ -11,24 +11,24 @@
 $comment = $dom->createComment("foobarbaz");
 try {
     var_dump($comment->substringData(0, 2**31+1));
-} catch (DOMException $e) {
-    echo $e->getMessage(), "\n";
+} catch (Throwable $e) {
+    echo $e::class, ': ', $e->getMessage(), "\n";
 }
 try {
     var_dump($comment->substringData(2**31+1, 0));
-} catch (DOMException $e) {
-    echo $e->getMessage(), "\n";
+} catch (Throwable $e) {
+    echo $e::class, ': ', $e->getMessage(), "\n";
 }
 try {
     var_dump($comment->substringData(100, 0));
-} catch (DOMException $e) {
-    echo $e->getMessage(), "\n";
+} catch (Throwable $e) {
+    echo $e::class, ': ', $e->getMessage(), "\n";
 }
 echo $dom->saveHtml($comment), "\n";

 ?>
 --EXPECT--
-Index Size Error
-Index Size Error
-Index Size Error
+DOMException: Index Size Error
+DOMException: Index Size Error
+DOMException: Index Size Error
 <!--foobarbaz-->
diff --git a/ext/dom/tests/modern/spec/CharacterData_substringData_negative_arguments.phpt b/ext/dom/tests/modern/spec/CharacterData_substringData_negative_arguments.phpt
index 28198d94d6d..5e980a1521b 100644
--- a/ext/dom/tests/modern/spec/CharacterData_substringData_negative_arguments.phpt
+++ b/ext/dom/tests/modern/spec/CharacterData_substringData_negative_arguments.phpt
@@ -13,8 +13,8 @@
 echo $dom->saveHtml($comment), "\n";
 try {
     var_dump($comment->substringData(-2, 2));
-} catch (DOMException $e) {
-    echo $e->getMessage(), "\n";
+} catch (Throwable $e) {
+    echo $e::class, ': ', $e->getMessage(), "\n";
 }
 echo $dom->saveHtml($comment), "\n";

@@ -24,5 +24,5 @@
 <!--foobarbaz-->
 string(7) "obarbaz"
 <!--foobarbaz-->
-Index Size Error
+DOMException: Index Size Error
 <!--foobarbaz-->
diff --git a/ext/dom/tests/modern/spec/CharacterData_substringData_negative_arguments_mod32.phpt b/ext/dom/tests/modern/spec/CharacterData_substringData_negative_arguments_mod32.phpt
index 7d38bd28d44..ef85193c35c 100644
--- a/ext/dom/tests/modern/spec/CharacterData_substringData_negative_arguments_mod32.phpt
+++ b/ext/dom/tests/modern/spec/CharacterData_substringData_negative_arguments_mod32.phpt
@@ -26,20 +26,20 @@
 $comment = $dom->createComment("foobarbaz");
 try {
     var_dump($comment->substringData(0, -1));
-} catch (DOMException $e) {
-    echo $e->getMessage(), "\n";
+} catch (Throwable $e) {
+    echo $e::class, ': ', $e->getMessage(), "\n";
 }
 echo $dom->saveHtml($comment), "\n";
 try {
     var_dump($comment->substringData(2, -(2**32 - 2)));
-} catch (DOMException $e) {
-    echo $e->getMessage(), "\n";
+} catch (Throwable $e) {
+    echo $e::class, ': ', $e->getMessage(), "\n";
 }
 echo $dom->saveHtml($comment), "\n";
 try {
     var_dump($comment->substringData(-(2**32 - 2), 2));
-} catch (DOMException $e) {
-    echo $e->getMessage(), "\n";
+} catch (Throwable $e) {
+    echo $e::class, ': ', $e->getMessage(), "\n";
 }
 echo $dom->saveHtml($comment), "\n";

@@ -53,9 +53,9 @@
 string(2) "ob"
 <!--foobarbaz-->
 --- Legacy behaviour ---
-Index Size Error
+DOMException: Index Size Error
 <!--foobarbaz-->
-Index Size Error
+DOMException: Index Size Error
 <!--foobarbaz-->
-Index Size Error
+DOMException: Index Size Error
 <!--foobarbaz-->
diff --git a/ext/dom/tests/modern/spec/Document_createAttributeNS.phpt b/ext/dom/tests/modern/spec/Document_createAttributeNS.phpt
index 6441ee60ef4..58f8b3e3e91 100644
--- a/ext/dom/tests/modern/spec/Document_createAttributeNS.phpt
+++ b/ext/dom/tests/modern/spec/Document_createAttributeNS.phpt
@@ -10,9 +10,9 @@
 function testErrorCase($dom, $ns, $qname) {
     try {
         $dom->createAttributeNS($ns, $qname);
-    } catch (DOMException $e) {
+    } catch (Throwable $e) {
         $ns_readable = is_null($ns) ? 'null' : "\"$ns\"";
-        echo "($ns_readable, \"$qname\"): {$e->getMessage()}\n";
+        echo "($ns_readable, \"$qname\"): ", $e::class, ': ', $e->getMessage(), "\n";
     }
 }

@@ -68,13 +68,13 @@ function testErrorCase($dom, $ns, $qname) {
 ?>
 --EXPECT--
 --- Error cases ---
-("", "bar:bar"): Namespace Error
-(null, "bar:bar"): Namespace Error
-("urn:a", "@"): Invalid Character Error
-("urn:a", "foo:bar:baz"): Invalid Character Error
-("http://www.w3.org/2000/xmlns", "xmlns"): Namespace Error
-("http://www.w3.org/2000/xmlns", "xmlns:bar"): Namespace Error
-("http://www.w3.org/2000/xmlns", "xml:foo"): Namespace Error
+("", "bar:bar"): DOMException: Namespace Error
+(null, "bar:bar"): DOMException: Namespace Error
+("urn:a", "@"): DOMException: Invalid Character Error
+("urn:a", "foo:bar:baz"): DOMException: Invalid Character Error
+("http://www.w3.org/2000/xmlns", "xmlns"): DOMException: Namespace Error
+("http://www.w3.org/2000/xmlns", "xmlns:bar"): DOMException: Namespace Error
+("http://www.w3.org/2000/xmlns", "xml:foo"): DOMException: Namespace Error

 --- Normal cases ---
 Attr: xmlns:foo
diff --git a/ext/dom/tests/modern/spec/Document_createElementNS.phpt b/ext/dom/tests/modern/spec/Document_createElementNS.phpt
index cbdbe5dfd98..050b46d03e2 100644
--- a/ext/dom/tests/modern/spec/Document_createElementNS.phpt
+++ b/ext/dom/tests/modern/spec/Document_createElementNS.phpt
@@ -32,8 +32,8 @@ function testError($dom, $namespaceURI, $qualifiedName)
     echo "($ns_readable, \"$qualifiedName\"): ";
     try {
         $dom->createElementNS($namespaceURI, $qualifiedName);
-    } catch (DOMException $e) {
-        echo $e->getMessage(), "\n";
+    } catch (Throwable $e) {
+        echo $e::class, ': ', $e->getMessage(), "\n";
     }
 }

@@ -89,8 +89,8 @@ function testError($dom, $namespaceURI, $qualifiedName)
 <xml>&amp;hello</xml>

 --- Error cases ---
-(NULL, "prefix:name"): Namespace Error
-("", "prefix:name"): Namespace Error
-("urn:foo", "@"): Invalid Character Error
-("http://www.w3.org/2000/xmlns/", "svg"): Namespace Error
-("urn:foo", "xml:xml"): Namespace Error
+(NULL, "prefix:name"): DOMException: Namespace Error
+("", "prefix:name"): DOMException: Namespace Error
+("urn:foo", "@"): DOMException: Invalid Character Error
+("http://www.w3.org/2000/xmlns/", "svg"): DOMException: Namespace Error
+("urn:foo", "xml:xml"): DOMException: Namespace Error
diff --git a/ext/dom/tests/modern/spec/Document_createElement_edge_cases.phpt b/ext/dom/tests/modern/spec/Document_createElement_edge_cases.phpt
index 6d8fc878b6c..ac31650f03f 100644
--- a/ext/dom/tests/modern/spec/Document_createElement_edge_cases.phpt
+++ b/ext/dom/tests/modern/spec/Document_createElement_edge_cases.phpt
@@ -8,16 +8,16 @@
 $dom = Dom\HTMLDocument::createEmpty();
 try {
     $dom->createElement('');
-} catch (DOMException $e) {
-    echo $e->getMessage(), "\n";
+} catch (Throwable $e) {
+    echo $e::class, ': ', $e->getMessage(), "\n";
 }
 try {
     $dom->createElement('$');
-} catch (DOMException $e) {
-    echo $e->getMessage(), "\n";
+} catch (Throwable $e) {
+    echo $e::class, ': ', $e->getMessage(), "\n";
 }

 ?>
 --EXPECT--
-Invalid Character Error
-Invalid Character Error
+DOMException: Invalid Character Error
+DOMException: Invalid Character Error
diff --git a/ext/dom/tests/modern/spec/Document_implementation_createDocumentType_errors.phpt b/ext/dom/tests/modern/spec/Document_implementation_createDocumentType_errors.phpt
index 74e17fb5a4f..bddf79c395c 100644
--- a/ext/dom/tests/modern/spec/Document_implementation_createDocumentType_errors.phpt
+++ b/ext/dom/tests/modern/spec/Document_implementation_createDocumentType_errors.phpt
@@ -8,22 +8,22 @@
 $dom = Dom\XMLDocument::createEmpty();
 try {
     $dom->implementation->createDocumentType("invalid name", "public", "system");
-} catch (DOMException $e) {
-    echo $e->getMessage(), "\n";
+} catch (Throwable $e) {
+    echo $e::class, ': ', $e->getMessage(), "\n";
 }
 try {
     $dom->implementation->createDocumentType("", "public", "system");
-} catch (DOMException $e) {
-    echo $e->getMessage(), "\n";
+} catch (Throwable $e) {
+    echo $e::class, ': ', $e->getMessage(), "\n";
 }
 try {
     $dom->implementation->createDocumentType("@", "", "");
-} catch (DOMException $e) {
-    echo $e->getMessage(), "\n";
+} catch (Throwable $e) {
+    echo $e::class, ': ', $e->getMessage(), "\n";
 }

 ?>
 --EXPECT--
-Namespace Error
-Namespace Error
-Namespace Error
+DOMException: Namespace Error
+DOMException: Namespace Error
+DOMException: Namespace Error
diff --git a/ext/dom/tests/modern/spec/Document_implementation_createDocument_errors.phpt b/ext/dom/tests/modern/spec/Document_implementation_createDocument_errors.phpt
index 673aed3ef55..b4376245988 100644
--- a/ext/dom/tests/modern/spec/Document_implementation_createDocument_errors.phpt
+++ b/ext/dom/tests/modern/spec/Document_implementation_createDocument_errors.phpt
@@ -9,17 +9,17 @@

 try {
     $dom->implementation->createDocument("urn:a", "@");
-} catch (DOMException $e) {
-    echo $e->getMessage(), "\n";
+} catch (Throwable $e) {
+    echo $e::class, ': ', $e->getMessage(), "\n";
 }

 try {
     $dom->implementation->createDocument("", "foo:bar");
-} catch (DOMException $e) {
-    echo $e->getMessage(), "\n";
+} catch (Throwable $e) {
+    echo $e::class, ': ', $e->getMessage(), "\n";
 }

 ?>
 --EXPECT--
-Invalid Character Error
-Namespace Error
+DOMException: Invalid Character Error
+DOMException: Namespace Error
diff --git a/ext/dom/tests/modern/spec/Document_implementation_same_object.phpt b/ext/dom/tests/modern/spec/Document_implementation_same_object.phpt
index 690b2bf6358..bcc735ab7c2 100644
--- a/ext/dom/tests/modern/spec/Document_implementation_same_object.phpt
+++ b/ext/dom/tests/modern/spec/Document_implementation_same_object.phpt
@@ -17,8 +17,8 @@

 try {
     clone $implementation;
-} catch (Error $e) {
-    echo $e->getMessage(), "\n";
+} catch (Throwable $e) {
+    echo $e::class, ': ', $e->getMessage(), "\n";
 }

 ?>
@@ -28,4 +28,4 @@
 bool(false)
 object(Dom\Implementation)#2 (0) {
 }
-Trying to clone an uncloneable object of class Dom\Implementation
+Error: Trying to clone an uncloneable object of class Dom\Implementation
diff --git a/ext/dom/tests/modern/spec/Document_importNode_not_supported.phpt b/ext/dom/tests/modern/spec/Document_importNode_not_supported.phpt
index 9f02411fd8b..7367e9fdcfd 100644
--- a/ext/dom/tests/modern/spec/Document_importNode_not_supported.phpt
+++ b/ext/dom/tests/modern/spec/Document_importNode_not_supported.phpt
@@ -13,12 +13,12 @@
 $dom = Dom\HTMLDocument::createEmpty();
 try {
     $dom->importNode($dom);
-} catch (DOMException $e) {
-    echo $e->getMessage(), "\n";
+} catch (Throwable $e) {
+    echo $e::class, ': ', $e->getMessage(), "\n";
 }

 ?>
 --EXPECTF--
 Warning: DOMDocument::importNode(): Cannot import: Node Type Not Supported in %s on line %d
 bool(false)
-Not Supported Error
+DOMException: Not Supported Error
diff --git a/ext/dom/tests/modern/spec/Element_insertAdjacentText.phpt b/ext/dom/tests/modern/spec/Element_insertAdjacentText.phpt
index ef466817de8..90eb1570b42 100644
--- a/ext/dom/tests/modern/spec/Element_insertAdjacentText.phpt
+++ b/ext/dom/tests/modern/spec/Element_insertAdjacentText.phpt
@@ -9,8 +9,8 @@
 $foo = $dom->appendChild($dom->createElement("foo"));
 try {
     $foo->insertAdjacentText(Dom\AdjacentPosition::BeforeBegin, "bar");
-} catch (DOMException $e) {
-    echo $e->getMessage(), "\n";
+} catch (Throwable $e) {
+    echo $e::class, ': ', $e->getMessage(), "\n";
 }

 $foo->insertAdjacentText(Dom\AdjacentPosition::AfterBegin, "bar");
@@ -23,7 +23,7 @@

 ?>
 --EXPECT--
-Cannot insert text as a child of a document
+DOMException: Cannot insert text as a child of a document
 <foo>barbaz</foo>
 string(3) "bar"
 string(3) "baz"
diff --git a/ext/dom/tests/modern/spec/Element_prefix_readonly.phpt b/ext/dom/tests/modern/spec/Element_prefix_readonly.phpt
index cb623f70298..79119f19769 100644
--- a/ext/dom/tests/modern/spec/Element_prefix_readonly.phpt
+++ b/ext/dom/tests/modern/spec/Element_prefix_readonly.phpt
@@ -8,11 +8,11 @@
 $div = $dom->createElement('div');
 try {
     $div->prefix = "foo";
-} catch (Error $e) {
-    echo $e->getMessage(), "\n";
+} catch (Throwable $e) {
+    echo $e::class, ': ', $e->getMessage(), "\n";
 }
 echo $dom->saveXml();
 ?>
 --EXPECT--
-Cannot modify private(set) property Dom\Element::$prefix from global scope
+Error: Cannot modify private(set) property Dom\Element::$prefix from global scope
 <?xml version="1.0" encoding="UTF-8" standalone="yes"?>
diff --git a/ext/dom/tests/modern/spec/Element_removeAttribute_edge_cases.phpt b/ext/dom/tests/modern/spec/Element_removeAttribute_edge_cases.phpt
index e50ef36e31f..9a5661b967f 100644
--- a/ext/dom/tests/modern/spec/Element_removeAttribute_edge_cases.phpt
+++ b/ext/dom/tests/modern/spec/Element_removeAttribute_edge_cases.phpt
@@ -8,10 +8,10 @@
 $dom = Dom\XMLDocument::createFromString('<root a="b"/>');
 try {
     $dom->documentElement->removeAttributeNode($dom->createAttribute('test'));
-} catch (DOMException $e) {
-    echo $e->getMessage(), "\n";
+} catch (Throwable $e) {
+    echo $e::class, ': ', $e->getMessage(), "\n";
 }

 ?>
 --EXPECT--
-Not Found Error
+DOMException: Not Found Error
diff --git a/ext/dom/tests/modern/spec/Element_setAttributeNS.phpt b/ext/dom/tests/modern/spec/Element_setAttributeNS.phpt
index a38048a47ce..1baacee2613 100644
--- a/ext/dom/tests/modern/spec/Element_setAttributeNS.phpt
+++ b/ext/dom/tests/modern/spec/Element_setAttributeNS.phpt
@@ -20,8 +20,8 @@

 try {
     $container->setAttributeNS("urn:a", "a:b:c", "");
-} catch (DOMException $e) {
-    echo $e->getMessage(), "\n";
+} catch (Throwable $e) {
+    echo $e::class, ': ', $e->getMessage(), "\n";
 }

 echo "--- ns attributes with same namespace but different prefix ---\n";
@@ -53,7 +53,7 @@
 string(9) "xmlns:foo"
 string(29) "http://www.w3.org/2000/xmlns/"
 --- name validation ---
-Invalid Character Error
+DOMException: Invalid Character Error
 --- ns attributes with same namespace but different prefix ---
 <container y:foo="2"></container>
 Attr: y:foo
diff --git a/ext/dom/tests/modern/spec/Element_setAttributeNode_inuse.phpt b/ext/dom/tests/modern/spec/Element_setAttributeNode_inuse.phpt
index f6509c07a19..a83c09b0c70 100644
--- a/ext/dom/tests/modern/spec/Element_setAttributeNode_inuse.phpt
+++ b/ext/dom/tests/modern/spec/Element_setAttributeNode_inuse.phpt
@@ -13,12 +13,12 @@
 $element = $container->appendChild($dom1->createElement("element"));
 try {
     $element->setAttributeNode($attr1);
-} catch (DOMException $e) {
-    echo $e->getMessage(), "\n";
+} catch (Throwable $e) {
+    echo $e::class, ': ', $e->getMessage(), "\n";
 }
 echo $dom1->saveHtml(), "\n";

 ?>
 --EXPECT--
-In Use Attribute Error
+DOMException: In Use Attribute Error
 <container my-attribute="1"><element></element></container>
diff --git a/ext/dom/tests/modern/spec/HTMLDocument_createCDATASection.phpt b/ext/dom/tests/modern/spec/HTMLDocument_createCDATASection.phpt
index 1787ae29f95..fb02c20c759 100644
--- a/ext/dom/tests/modern/spec/HTMLDocument_createCDATASection.phpt
+++ b/ext/dom/tests/modern/spec/HTMLDocument_createCDATASection.phpt
@@ -7,30 +7,30 @@
 $dom = Dom\HTMLDocument::createEmpty();
 try {
     $dom->createCDATASection("foo");
-} catch (DOMException $e) {
+} catch (Throwable $e) {
     var_dump($e->getCode());
-    echo $e->getMessage(), "\n";
+    echo $e::class, ': ', $e->getMessage(), "\n";
 }
 try {
     $dom->createCDATASection("]]>");
-} catch (DOMException $e) {
+} catch (Throwable $e) {
     var_dump($e->getCode());
-    echo $e->getMessage(), "\n";
+    echo $e::class, ': ', $e->getMessage(), "\n";
 }

 $dom = Dom\XMLDocument::createEmpty();
 try {
     $dom->createCDATASection("]]>");
-} catch (DOMException $e) {
+} catch (Throwable $e) {
     var_dump($e->getCode());
-    echo $e->getMessage(), "\n";
+    echo $e::class, ': ', $e->getMessage(), "\n";
 }
 $dom->createCDATASection("]>");
 ?>
 --EXPECT--
 int(9)
-This operation is not supported for HTML documents
+DOMException: This operation is not supported for HTML documents
 int(9)
-This operation is not supported for HTML documents
+DOMException: This operation is not supported for HTML documents
 int(5)
-Invalid character sequence "]]>" in CDATA section
+DOMException: Invalid character sequence "]]>" in CDATA section
diff --git a/ext/dom/tests/modern/spec/HTMLDocument_createProcessingInstruction.phpt b/ext/dom/tests/modern/spec/HTMLDocument_createProcessingInstruction.phpt
index f1a60b875b1..23c8e0a0d7b 100644
--- a/ext/dom/tests/modern/spec/HTMLDocument_createProcessingInstruction.phpt
+++ b/ext/dom/tests/modern/spec/HTMLDocument_createProcessingInstruction.phpt
@@ -7,21 +7,21 @@
 $dom = Dom\HTMLDocument::createEmpty();
 try {
     $dom->createProcessingInstruction("?>", "");
-} catch (DOMException $e) {
+} catch (Throwable $e) {
     var_dump($e->getCode());
-    echo $e->getMessage(), "\n";
+    echo $e::class, ': ', $e->getMessage(), "\n";
 }
 try {
     $dom->createProcessingInstruction("?>", "?>");
-} catch (DOMException $e) {
+} catch (Throwable $e) {
     var_dump($e->getCode());
-    echo $e->getMessage(), "\n";
+    echo $e::class, ': ', $e->getMessage(), "\n";
 }
 try {
     $dom->createProcessingInstruction("target", "?>");
-} catch (DOMException $e) {
+} catch (Throwable $e) {
     var_dump($e->getCode());
-    echo $e->getMessage(), "\n";
+    echo $e::class, ': ', $e->getMessage(), "\n";
 }
 $dom->appendChild($dom->createProcessingInstruction("foo", ""));
 $dom->appendChild($dom->createProcessingInstruction("foo", "bar"));
@@ -29,9 +29,9 @@
 ?>
 --EXPECT--
 int(5)
-Invalid Character Error
+DOMException: Invalid Character Error
 int(5)
-Invalid Character Error
+DOMException: Invalid Character Error
 int(5)
-Invalid character sequence "?>" in processing instruction
+DOMException: Invalid character sequence "?>" in processing instruction
 <?foo ><?foo bar>
diff --git a/ext/dom/tests/modern/spec/NamedNodeMap_dimensions.phpt b/ext/dom/tests/modern/spec/NamedNodeMap_dimensions.phpt
index cf446881559..c2f8f4ba555 100644
--- a/ext/dom/tests/modern/spec/NamedNodeMap_dimensions.phpt
+++ b/ext/dom/tests/modern/spec/NamedNodeMap_dimensions.phpt
@@ -14,8 +14,8 @@
     echo "--- ", json_encode($value), " ---\n";
     try {
         var_dump($attributes[$value] ? $attributes[$value]->nodeName : "N/A", isset($attributes[$value]), empty($attributes[$value]));
-    } catch (Error $e) {
-        echo $e->getMessage(), "\n";
+    } catch (Throwable $e) {
+        echo $e::class, ': ', $e->getMessage(), "\n";
     }
 }

@@ -58,9 +58,9 @@
 bool(true)
 bool(false)
 --- true ---
-Cannot access offset of type bool on Dom\NamedNodeMap
+TypeError: Cannot access offset of type bool on Dom\NamedNodeMap
 --- null ---
-Cannot access offset of type null on Dom\NamedNodeMap
+TypeError: Cannot access offset of type null on Dom\NamedNodeMap
 --- "0" ---
 string(1) "a"
 bool(true)
diff --git a/ext/dom/tests/modern/spec/NamedNodeMap_dimensions_errors.phpt b/ext/dom/tests/modern/spec/NamedNodeMap_dimensions_errors.phpt
index 848b1a2c0b0..c6a18db4373 100644
--- a/ext/dom/tests/modern/spec/NamedNodeMap_dimensions_errors.phpt
+++ b/ext/dom/tests/modern/spec/NamedNodeMap_dimensions_errors.phpt
@@ -10,10 +10,10 @@

 try {
     $attributes[][0] = 1;
-} catch (Error $e) {
-    echo $e->getMessage(), "\n";
+} catch (Throwable $e) {
+    echo $e::class, ': ', $e->getMessage(), "\n";
 }

 ?>
 --EXPECT--
-Cannot append to Dom\NamedNodeMap
+Error: Cannot append to Dom\NamedNodeMap
diff --git a/ext/dom/tests/modern/spec/NodeList_dimensions.phpt b/ext/dom/tests/modern/spec/NodeList_dimensions.phpt
index f5fe6480e64..710a48b6069 100644
--- a/ext/dom/tests/modern/spec/NodeList_dimensions.phpt
+++ b/ext/dom/tests/modern/spec/NodeList_dimensions.phpt
@@ -14,8 +14,8 @@
     echo "--- ", json_encode($value), " ---\n";
     try {
         var_dump($children[$value] ? $children[$value]->nodeName : "N/A", isset($children[$value]), empty($children[$value]));
-    } catch (Error $e) {
-        echo $e->getMessage(), "\n";
+    } catch (Throwable $e) {
+        echo $e::class, ': ', $e->getMessage(), "\n";
     }
 }

@@ -58,9 +58,9 @@
 bool(true)
 bool(false)
 --- true ---
-Cannot access offset of type bool on Dom\NodeList
+TypeError: Cannot access offset of type bool on Dom\NodeList
 --- null ---
-Cannot access offset of type null on Dom\NodeList
+TypeError: Cannot access offset of type null on Dom\NodeList
 --- "0" ---
 string(1) "a"
 bool(true)
@@ -70,6 +70,6 @@
 bool(true)
 bool(false)
 --- "" ---
-Cannot access offset of type string on Dom\NodeList
+TypeError: Cannot access offset of type string on Dom\NodeList
 --- "foo" ---
-Cannot access offset of type string on Dom\NodeList
+TypeError: Cannot access offset of type string on Dom\NodeList
diff --git a/ext/dom/tests/modern/spec/NodeList_dimensions_errors.phpt b/ext/dom/tests/modern/spec/NodeList_dimensions_errors.phpt
index bfb882823b7..d5c84550b82 100644
--- a/ext/dom/tests/modern/spec/NodeList_dimensions_errors.phpt
+++ b/ext/dom/tests/modern/spec/NodeList_dimensions_errors.phpt
@@ -10,10 +10,10 @@

 try {
     $children[][0] = 1;
-} catch (Error $e) {
-    echo $e->getMessage(), "\n";
+} catch (Throwable $e) {
+    echo $e::class, ': ', $e->getMessage(), "\n";
 }

 ?>
 --EXPECT--
-Cannot append to Dom\NodeList
+Error: Cannot append to Dom\NodeList
diff --git a/ext/dom/tests/modern/spec/Node_appendChild_attribute.phpt b/ext/dom/tests/modern/spec/Node_appendChild_attribute.phpt
index 3e3a5674c6a..d0b422cb4f7 100644
--- a/ext/dom/tests/modern/spec/Node_appendChild_attribute.phpt
+++ b/ext/dom/tests/modern/spec/Node_appendChild_attribute.phpt
@@ -12,13 +12,13 @@
 $attr->value = "hello";
 try {
     $element->appendChild($attr);
-} catch (DOMException $e) {
-    echo $e->getMessage(), "\n";
+} catch (Throwable $e) {
+    echo $e::class, ': ', $e->getMessage(), "\n";
 }

 var_dump($attr->value);

 ?>
 --EXPECT--
-Hierarchy Request Error
+DOMException: Hierarchy Request Error
 string(5) "hello"
diff --git a/ext/dom/tests/modern/spec/Node_appendChild_fragment_multiple_elements.phpt b/ext/dom/tests/modern/spec/Node_appendChild_fragment_multiple_elements.phpt
index fc62d89811b..3a1cd004bcb 100644
--- a/ext/dom/tests/modern/spec/Node_appendChild_fragment_multiple_elements.phpt
+++ b/ext/dom/tests/modern/spec/Node_appendChild_fragment_multiple_elements.phpt
@@ -13,13 +13,13 @@

 try {
     $dom->appendChild($fragment);
-} catch (DOMException $e) {
-    echo $e->getMessage(), "\n";
+} catch (Throwable $e) {
+    echo $e::class, ': ', $e->getMessage(), "\n";
 }

 echo $dom->saveXml($fragment), "\n";

 ?>
 --EXPECT--
-Cannot have more than one element child in a document
+DOMException: Cannot have more than one element child in a document
 <foo/><bar/>
diff --git a/ext/dom/tests/modern/spec/Node_appendChild_invalid_parent.phpt b/ext/dom/tests/modern/spec/Node_appendChild_invalid_parent.phpt
index af99bfc3805..d62df916f3c 100644
--- a/ext/dom/tests/modern/spec/Node_appendChild_invalid_parent.phpt
+++ b/ext/dom/tests/modern/spec/Node_appendChild_invalid_parent.phpt
@@ -14,31 +14,31 @@

 try {
     $text->appendChild($dom->createElement('br'));
-} catch (DOMException $e) {
-    echo $e->getMessage(), "\n";
+} catch (Throwable $e) {
+    echo $e::class, ': ', $e->getMessage(), "\n";
 }

 try {
     $cdata->appendChild($dom->createElement('br'));
-} catch (DOMException $e) {
-    echo $e->getMessage(), "\n";
+} catch (Throwable $e) {
+    echo $e::class, ': ', $e->getMessage(), "\n";
 }

 try {
     $pi->appendChild($dom->createElement('br'));
-} catch (DOMException $e) {
-    echo $e->getMessage(), "\n";
+} catch (Throwable $e) {
+    echo $e::class, ': ', $e->getMessage(), "\n";
 }

 try {
     $attr->appendChild($dom->createElement('br'));
-} catch (DOMException $e) {
-    echo $e->getMessage(), "\n";
+} catch (Throwable $e) {
+    echo $e::class, ': ', $e->getMessage(), "\n";
 }

 ?>
 --EXPECT--
-Hierarchy Request Error
-Hierarchy Request Error
-Hierarchy Request Error
-Hierarchy Request Error
+DOMException: Hierarchy Request Error
+DOMException: Hierarchy Request Error
+DOMException: Hierarchy Request Error
+DOMException: Hierarchy Request Error
diff --git a/ext/dom/tests/modern/spec/Node_cloneNode_copy_document_properties.phpt b/ext/dom/tests/modern/spec/Node_cloneNode_copy_document_properties.phpt
index 7894aa0a313..e9352b02825 100644
--- a/ext/dom/tests/modern/spec/Node_cloneNode_copy_document_properties.phpt
+++ b/ext/dom/tests/modern/spec/Node_cloneNode_copy_document_properties.phpt
@@ -12,10 +12,10 @@

 try {
     $dom->prepend($dom->createElement("bar"));
-} catch (DOMException $e) {
-    echo $e->getMessage(), "\n";
+} catch (Throwable $e) {
+    echo $e::class, ': ', $e->getMessage(), "\n";
 }

 ?>
 --EXPECT--
-Cannot have more than one element child in a document
+DOMException: Cannot have more than one element child in a document
diff --git a/ext/dom/tests/modern/spec/Node_insertBefore_01.phpt b/ext/dom/tests/modern/spec/Node_insertBefore_01.phpt
index 967334bbeba..85527ad89e8 100644
--- a/ext/dom/tests/modern/spec/Node_insertBefore_01.phpt
+++ b/ext/dom/tests/modern/spec/Node_insertBefore_01.phpt
@@ -13,13 +13,13 @@

 try {
     $dom->insertBefore($fragment, $dom->doctype);
-} catch (DOMException $e) {
-    echo $e->getMessage(), "\n";
+} catch (Throwable $e) {
+    echo $e::class, ': ', $e->getMessage(), "\n";
 }

 echo $dom->saveHtml(), "\n";

 ?>
 --EXPECT--
-Document types must be the first child in a document
+DOMException: Document types must be the first child in a document
 <!DOCTYPE html>
diff --git a/ext/dom/tests/modern/spec/Node_insertBefore_02.phpt b/ext/dom/tests/modern/spec/Node_insertBefore_02.phpt
index 390dba0f176..df616b94035 100644
--- a/ext/dom/tests/modern/spec/Node_insertBefore_02.phpt
+++ b/ext/dom/tests/modern/spec/Node_insertBefore_02.phpt
@@ -12,13 +12,13 @@

 try {
     $dom->insertBefore($fragment, $dom->documentElement);
-} catch (DOMException $e) {
-    echo $e->getMessage(), "\n";
+} catch (Throwable $e) {
+    echo $e::class, ': ', $e->getMessage(), "\n";
 }

 echo $dom->saveHtml(), "\n";

 ?>
 --EXPECT--
-Cannot have more than one element child in a document
+DOMException: Cannot have more than one element child in a document
 <!DOCTYPE html><html><head></head><body></body></html>
diff --git a/ext/dom/tests/modern/spec/Node_replaceChild_edge_cases.phpt b/ext/dom/tests/modern/spec/Node_replaceChild_edge_cases.phpt
index afa6d1e8a81..b35b5f0d7d5 100644
--- a/ext/dom/tests/modern/spec/Node_replaceChild_edge_cases.phpt
+++ b/ext/dom/tests/modern/spec/Node_replaceChild_edge_cases.phpt
@@ -17,30 +17,30 @@
 $comment = $dom->createComment('This is a comment');
 try {
     $comment->replaceChild($comment, $dom->createElement("old-child"));
-} catch (DOMException $e) {
-    echo $e->getMessage(), "\n";
+} catch (Throwable $e) {
+    echo $e::class, ': ', $e->getMessage(), "\n";
 }

 echo "--- Node is an inclusive ancestor of parent ---\n";

 try {
     $parent->replaceChild($parent, $child);
-} catch (DOMException $e) {
-    echo $e->getMessage(), "\n";
+} catch (Throwable $e) {
+    echo $e::class, ': ', $e->getMessage(), "\n";
 }

 try {
     $parent->replaceChild($dom, $child);
-} catch (DOMException $e) {
-    echo $e->getMessage(), "\n";
+} catch (Throwable $e) {
+    echo $e::class, ': ', $e->getMessage(), "\n";
 }

 echo "--- Child's parent is not parent ---\n";

 try {
     $parent->replaceChild($dom->createElement("new-child"), $dom->createElement("old-child"));
-} catch (DOMException $e) {
-    echo $e->getMessage(), "\n";
+} catch (Throwable $e) {
+    echo $e::class, ': ', $e->getMessage(), "\n";
 }

 echo "--- Invalid child to replace with ---\n";
@@ -48,24 +48,24 @@
 try {
     $entityReference = $dom->importNode(Dom\XMLDocument::createEmpty()->createEntityReference("foo"));
     $parent->replaceChild($entityReference, $child);
-} catch (DOMException $e) {
-    echo $e->getMessage(), "\n";
+} catch (Throwable $e) {
+    echo $e::class, ': ', $e->getMessage(), "\n";
 }

 echo "--- Replace element with text in document root ---\n";

 try {
     $dom->replaceChild($dom->createTextNode("text"), $parent);
-} catch (DOMException $e) {
-    echo $e->getMessage(), "\n";
+} catch (Throwable $e) {
+    echo $e::class, ': ', $e->getMessage(), "\n";
 }

 echo "--- Replace child element with doctype inside element ---\n";

 try {
     $parent->replaceChild($dom->doctype, $child);
-} catch (DOMException $e) {
-    echo $e->getMessage(), "\n";
+} catch (Throwable $e) {
+    echo $e::class, ': ', $e->getMessage(), "\n";
 }

 echo "--- Replace element with fragment containing multiple elements ---\n";
@@ -76,8 +76,8 @@

 try {
     $dom->replaceChild($fragment, $parent);
-} catch (DOMException $e) {
-    echo $e->getMessage(), "\n";
+} catch (Throwable $e) {
+    echo $e::class, ': ', $e->getMessage(), "\n";
 }

 echo "--- Replace comment in document causing more than two elements ---\n";
@@ -85,24 +85,24 @@
 $comment = $dom->appendChild($dom->createComment("comment"));
 try {
     $dom->replaceChild($dom->createElement("new-child"), $comment);
-} catch (DOMException $e) {
-    echo $e->getMessage(), "\n";
+} catch (Throwable $e) {
+    echo $e::class, ': ', $e->getMessage(), "\n";
 }

 echo "--- Replace dtd with element ---\n";

 try {
     $dom->replaceChild($dom->createElement("new-child"), $dom->doctype);
-} catch (DOMException $e) {
-    echo $e->getMessage(), "\n";
+} catch (Throwable $e) {
+    echo $e::class, ': ', $e->getMessage(), "\n";
 }

 echo "--- Replace element with another dtd ---\n";

 try {
     $dom->replaceChild($dom->doctype, $parent);
-} catch (DOMException $e) {
-    echo $e->getMessage(), "\n";
+} catch (Throwable $e) {
+    echo $e::class, ': ', $e->getMessage(), "\n";
 }

 echo "--- Replace parent with itself ---\n";
@@ -120,26 +120,26 @@
 ?>
 --EXPECT--
 --- Wrong parent node type ---
-Hierarchy Request Error
+DOMException: Hierarchy Request Error
 --- Node is an inclusive ancestor of parent ---
-Hierarchy Request Error
-Hierarchy Request Error
+DOMException: Hierarchy Request Error
+DOMException: Hierarchy Request Error
 --- Child's parent is not parent ---
-Not Found Error
+DOMException: Not Found Error
 --- Invalid child to replace with ---
-Hierarchy Request Error
+DOMException: Hierarchy Request Error
 --- Replace element with text in document root ---
-Cannot insert text as a child of a document
+DOMException: Cannot insert text as a child of a document
 --- Replace child element with doctype inside element ---
-Cannot insert a document type into anything other than a document
+DOMException: Cannot insert a document type into anything other than a document
 --- Replace element with fragment containing multiple elements ---
-Cannot have more than one element child in a document
+DOMException: Cannot have more than one element child in a document
 --- Replace comment in document causing more than two elements ---
-Cannot have more than one element child in a document
+DOMException: Cannot have more than one element child in a document
 --- Replace dtd with element ---
-Cannot have more than one element child in a document
+DOMException: Cannot have more than one element child in a document
 --- Replace element with another dtd ---
-Document types must be the first child in a document
+DOMException: Document types must be the first child in a document
 --- Replace parent with itself ---
 <!DOCTYPE html><parent><child></child></parent><!--comment-->
 --- Replace parent with single-child fragment ---
diff --git a/ext/dom/tests/modern/spec/ParentNode_append_exception_consistency.phpt b/ext/dom/tests/modern/spec/ParentNode_append_exception_consistency.phpt
index a88b4fc808b..3a2af3d4478 100644
--- a/ext/dom/tests/modern/spec/ParentNode_append_exception_consistency.phpt
+++ b/ext/dom/tests/modern/spec/ParentNode_append_exception_consistency.phpt
@@ -10,14 +10,14 @@
 $fragment->append($dom->createElement("bar"));
 try {
     $dom->append($fragment);
-} catch (DOMException $e) {
-    echo "Exception: " . $e->getMessage() . "\n";
+} catch (Throwable $e) {
+    echo $e::class, ': ', $e->getMessage(), "\n";
 }

 var_dump($element->parentNode);
 ?>
 --EXPECT--
-Exception: Cannot have more than one element child in a document
+DOMException: Cannot have more than one element child in a document
 object(Dom\DocumentFragment)#2 (18) {
   ["children"]=>
   string(22) "(object value omitted)"
diff --git a/ext/dom/tests/modern/spec/ParentNode_edge_case.phpt b/ext/dom/tests/modern/spec/ParentNode_edge_case.phpt
index 367f1437c67..302b9a8032c 100644
--- a/ext/dom/tests/modern/spec/ParentNode_edge_case.phpt
+++ b/ext/dom/tests/modern/spec/ParentNode_edge_case.phpt
@@ -9,10 +9,10 @@
 $container = $dom->createElement('container');
 try {
     $container->append($dom);
-} catch (DOMException $e) {
-    echo $e->getMessage(), "\n";
+} catch (Throwable $e) {
+    echo $e::class, ': ', $e->getMessage(), "\n";
 }

 ?>
 --EXPECT--
-Hierarchy Request Error
+DOMException: Hierarchy Request Error
diff --git a/ext/dom/tests/modern/spec/ParentNode_hierarchy_text_nodes.phpt b/ext/dom/tests/modern/spec/ParentNode_hierarchy_text_nodes.phpt
index f81450ca261..1e58ad9afa9 100644
--- a/ext/dom/tests/modern/spec/ParentNode_hierarchy_text_nodes.phpt
+++ b/ext/dom/tests/modern/spec/ParentNode_hierarchy_text_nodes.phpt
@@ -9,21 +9,21 @@

 try {
     $dom->append("bar");
-} catch (DOMException $e) {
-    echo "Exception: " . $e->getMessage() . "\n";
+} catch (Throwable $e) {
+    echo $e::class, ': ', $e->getMessage(), "\n";
 }

 try {
     $dom->append($dom->createTextNode("bar"));
-} catch (DOMException $e) {
-    echo "Exception: " . $e->getMessage() . "\n";
+} catch (Throwable $e) {
+    echo $e::class, ': ', $e->getMessage(), "\n";
 }

 $text = $dom->createTextNode("bar");
 try {
     $dom->append($text);
-} catch (DOMException $e) {
-    echo "Exception: " . $e->getMessage() . "\n";
+} catch (Throwable $e) {
+    echo $e::class, ': ', $e->getMessage(), "\n";
 }

 var_dump($text->parentNode);
@@ -33,15 +33,15 @@
 $text = $element->appendChild($dom->createTextNode("text"));
 try {
     $dom->append($text);
-} catch (DOMException $e) {
-    echo "Exception: " . $e->getMessage() . "\n";
+} catch (Throwable $e) {
+    echo $e::class, ': ', $e->getMessage(), "\n";
 }

 ?>
 --EXPECT--
-Exception: Cannot insert text as a child of a document
-Exception: Cannot insert text as a child of a document
-Exception: Cannot insert text as a child of a document
+DOMException: Cannot insert text as a child of a document
+DOMException: Cannot insert text as a child of a document
+DOMException: Cannot insert text as a child of a document
 NULL
 string(3) "bar"
-Exception: Cannot insert text as a child of a document
+DOMException: Cannot insert text as a child of a document
diff --git a/ext/dom/tests/modern/spec/Text_splitText_edge_case.phpt b/ext/dom/tests/modern/spec/Text_splitText_edge_case.phpt
index 4bd79b9b4a8..41785ee7b9c 100644
--- a/ext/dom/tests/modern/spec/Text_splitText_edge_case.phpt
+++ b/ext/dom/tests/modern/spec/Text_splitText_edge_case.phpt
@@ -9,16 +9,16 @@
 var_dump($text->splitText(5)->wholeText);
 try {
     var_dump($text->splitText(-1));
-} catch (ValueError $e) {
-  echo $e->getMessage(), "\n";
+} catch (Throwable $e) {
+  echo $e::class, ': ', $e->getMessage(), "\n";
 }
 try {
     var_dump($text->splitText(200));
-} catch (DOMException $e) {
-  echo $e->getMessage(), "\n";
+} catch (Throwable $e) {
+  echo $e::class, ': ', $e->getMessage(), "\n";
 }
 ?>
 --EXPECT--
 string(7) " World!"
-Dom\Text::splitText(): Argument #1 ($offset) must be greater than or equal to 0
-Index Size Error
+ValueError: Dom\Text::splitText(): Argument #1 ($offset) must be greater than or equal to 0
+DOMException: Index Size Error
diff --git a/ext/dom/tests/modern/spec/XMLDocument_version.phpt b/ext/dom/tests/modern/spec/XMLDocument_version.phpt
index 82f38839ea2..125c8027ba7 100644
--- a/ext/dom/tests/modern/spec/XMLDocument_version.phpt
+++ b/ext/dom/tests/modern/spec/XMLDocument_version.phpt
@@ -11,8 +11,8 @@
 foreach (['0.1', '1.0', '1.1', '', 'foo'] as $version) {
     try {
         $dom->xmlVersion = $version;
-    } catch (ValueError $e) {
-        echo $e->getMessage(), "\n";
+    } catch (Throwable $e) {
+        echo $e::class, ': ', $e->getMessage(), "\n";
     }
     var_dump($dom->xmlVersion);
 }
@@ -20,11 +20,11 @@
 ?>
 --EXPECT--
 string(3) "1.0"
-Invalid XML version
+ValueError: Invalid XML version
 string(3) "1.0"
 string(3) "1.0"
 string(3) "1.1"
-Invalid XML version
+ValueError: Invalid XML version
 string(3) "1.1"
-Invalid XML version
+ValueError: Invalid XML version
 string(3) "1.1"
diff --git a/ext/dom/tests/modern/spec/appendChild_dtd_legacy.phpt b/ext/dom/tests/modern/spec/appendChild_dtd_legacy.phpt
index 20a69b3b545..673d2b3519b 100644
--- a/ext/dom/tests/modern/spec/appendChild_dtd_legacy.phpt
+++ b/ext/dom/tests/modern/spec/appendChild_dtd_legacy.phpt
@@ -24,15 +24,15 @@
 $other->appendChild($doctype);
 try {
     $other->appendChild($other->implementation->createDocumentType('doc', '', ''));
-} catch (DOMException $e) {
-    echo $e->getMessage(), "\n";
+} catch (Throwable $e) {
+    echo $e::class, ': ', $e->getMessage(), "\n";
 }
 echo $other->saveXml();

 ?>
 --EXPECT--
 Found entity: foo
-A document may only contain one document type
+DOMException: A document may only contain one document type
 <?xml version="1.0"?>
 <!DOCTYPE doc [
 <!ENTITY foo "bar">
diff --git a/ext/dom/tests/modern/spec/append_text_nodes_invalid_hierarchy.phpt b/ext/dom/tests/modern/spec/append_text_nodes_invalid_hierarchy.phpt
index ea530d675c3..ffa90a3bd9d 100644
--- a/ext/dom/tests/modern/spec/append_text_nodes_invalid_hierarchy.phpt
+++ b/ext/dom/tests/modern/spec/append_text_nodes_invalid_hierarchy.phpt
@@ -9,20 +9,20 @@

 try {
     $dom->append("foo", "bar", "baz", $dom);
-} catch (DOMException $e) {
-    echo $e->getMessage(), "\n";
+} catch (Throwable $e) {
+    echo $e::class, ': ', $e->getMessage(), "\n";
 }

 try {
     $dom->append("foo", "bar", "baz");
-} catch (DOMException $e) {
-    echo $e->getMessage(), "\n";
+} catch (Throwable $e) {
+    echo $e::class, ': ', $e->getMessage(), "\n";
 }

 var_dump($dom->saveHtml());

 ?>
 --EXPECT--
-Hierarchy Request Error
-Cannot insert text as a child of a document
+DOMException: Hierarchy Request Error
+DOMException: Cannot insert text as a child of a document
 string(0) ""
diff --git a/ext/dom/tests/modern/spec/documentURI_URL.phpt b/ext/dom/tests/modern/spec/documentURI_URL.phpt
index 3e5a797eae6..3ec21156b44 100644
--- a/ext/dom/tests/modern/spec/documentURI_URL.phpt
+++ b/ext/dom/tests/modern/spec/documentURI_URL.phpt
@@ -13,8 +13,8 @@
     $dom->URL = NULL;
     var_dump($dom->documentURI);
     var_dump($dom->URL);
-} catch (TypeError $e) {
-    echo $e->getMessage(), "\n";
+} catch (Throwable $e) {
+    echo $e::class, ': ', $e->getMessage(), "\n";
 }

 $dom->URL = "";
@@ -29,7 +29,7 @@
 --EXPECTF--
 string(%d) "%s"
 string(%d) "%s"
-Cannot assign null to property Dom\Document::$URL of type string
+TypeError: Cannot assign null to property Dom\Document::$URL of type string
 string(0) ""
 string(0) ""
 string(%d) "%s"
diff --git a/ext/dom/tests/modern/spec/pre_insertion_validation.phpt b/ext/dom/tests/modern/spec/pre_insertion_validation.phpt
index d16e3ffad9d..67c464a3bdd 100644
--- a/ext/dom/tests/modern/spec/pre_insertion_validation.phpt
+++ b/ext/dom/tests/modern/spec/pre_insertion_validation.phpt
@@ -12,18 +12,18 @@

 try {
     $dom->append("foo", "bar", "baz");
-} catch (DOMException $e) {
-    echo "Exception: " . $e->getMessage() . "\n";
+} catch (Throwable $e) {
+    echo $e::class, ': ', $e->getMessage(), "\n";
 }
 try {
     $dom->append($dom->createTextNode("text node"));
-} catch (DOMException $e) {
-    echo "Exception: " . $e->getMessage() . "\n";
+} catch (Throwable $e) {
+    echo $e::class, ': ', $e->getMessage(), "\n";
 }
 try {
     $dom->append($dom->createCDATASection("text node"));
-} catch (DOMException $e) {
-    echo "Exception: " . $e->getMessage() . "\n";
+} catch (Throwable $e) {
+    echo $e::class, ': ', $e->getMessage(), "\n";
 }

 echo "--- Trying to insert doctype into not a document ---\n";
@@ -31,16 +31,16 @@
 $element = $dom->createElement("foo");
 try {
     $element->append($doctype);
-} catch (DOMException $e) {
-    echo "Exception: " . $e->getMessage() . "\n";
+} catch (Throwable $e) {
+    echo $e::class, ': ', $e->getMessage(), "\n";
 }

 echo "--- Trying to insert doctype at the wrong place in a document ---\n";

 try {
     $dom->append($doctype);
-} catch (DOMException $e) {
-    echo "Exception: " . $e->getMessage() . "\n";
+} catch (Throwable $e) {
+    echo $e::class, ': ', $e->getMessage(), "\n";
 }

 echo "--- Prepend doctype in a document should work ---\n";
@@ -51,8 +51,8 @@

 try {
     $dom->append($dom->createElement("foo"));
-} catch (DOMException $e) {
-    echo "Exception: " . $e->getMessage() . "\n";
+} catch (Throwable $e) {
+    echo $e::class, ': ', $e->getMessage(), "\n";
 }

 echo "--- Trying to insert an element before a document type ---\n";
@@ -60,8 +60,8 @@
 $dom->documentElement->remove();
 try {
     $dom->prepend($element);
-} catch (DOMException $e) {
-    echo "Exception: " . $e->getMessage() . "\n";
+} catch (Throwable $e) {
+    echo $e::class, ': ', $e->getMessage(), "\n";
 }

 echo "--- Document output ---\n";
@@ -76,8 +76,8 @@
 $fragment->append($dom->createElement("bar"));
 try {
     $dom->append($fragment);
-} catch (DOMException $e) {
-    echo "Exception: " . $e->getMessage() . "\n";
+} catch (Throwable $e) {
+    echo $e::class, ': ', $e->getMessage(), "\n";
 }

 echo "--- Document fragment edge cases with text ---\n";
@@ -88,30 +88,30 @@
 $fragment->append($dom->createCDATASection("bar"));
 try {
     $dom->append($fragment);
-} catch (DOMException $e) {
-    echo "Exception: " . $e->getMessage() . "\n";
+} catch (Throwable $e) {
+    echo $e::class, ': ', $e->getMessage(), "\n";
 }

 ?>
 --EXPECT--
 --- Trying to insert text node into the document ---
-Exception: Cannot insert text as a child of a document
-Exception: Cannot insert text as a child of a document
-Exception: Cannot insert text as a child of a document
+DOMException: Cannot insert text as a child of a document
+DOMException: Cannot insert text as a child of a document
+DOMException: Cannot insert text as a child of a document
 --- Trying to insert doctype into not a document ---
-Exception: Cannot insert a document type into anything other than a document
+DOMException: Cannot insert a document type into anything other than a document
 --- Trying to insert doctype at the wrong place in a document ---
-Exception: Document types must be the first child in a document
+DOMException: Document types must be the first child in a document
 --- Prepend doctype in a document should work ---
 --- Trying to create multiple document roots ---
-Exception: Cannot have more than one element child in a document
+DOMException: Cannot have more than one element child in a document
 --- Trying to insert an element before a document type ---
-Exception: Document types must be the first child in a document
+DOMException: Document types must be the first child in a document
 --- Document output ---
 <?xml version="1.0" encoding="UTF-8"?>
 <!DOCTYPE root>

 --- Document fragment edge cases with multiple elements ---
-Exception: Cannot have more than one element child in a document
+DOMException: Cannot have more than one element child in a document
 --- Document fragment edge cases with text ---
-Exception: Cannot insert text as a child of a document
+DOMException: Cannot insert text as a child of a document
diff --git a/ext/dom/tests/modern/spec/textContent_edge_cases.phpt b/ext/dom/tests/modern/spec/textContent_edge_cases.phpt
index 2252013c7a3..cc26feea8fe 100644
--- a/ext/dom/tests/modern/spec/textContent_edge_cases.phpt
+++ b/ext/dom/tests/modern/spec/textContent_edge_cases.phpt
@@ -11,8 +11,8 @@
 var_dump($dom->textContent);
 try {
     $dom->textContent = "foo";
-} catch (Error $e) {
-    echo $e->getMessage(), "\n";
+} catch (Throwable $e) {
+    echo $e::class, ': ', $e->getMessage(), "\n";
 }

 $container = $dom->documentElement;
@@ -39,7 +39,7 @@
 ?>
 --EXPECT--
 document text content: NULL
-Cannot modify readonly property Dom\XMLDocument::$textContent
+Error: Cannot modify readonly property Dom\XMLDocument::$textContent
 text node text content: string(4) "text"
 pi node text content: string(5) "value"
 text node text content: string(0) ""
diff --git a/ext/dom/tests/modern/token_list/add_errors.phpt b/ext/dom/tests/modern/token_list/add_errors.phpt
index 94db0d29311..070558edc4c 100644
--- a/ext/dom/tests/modern/token_list/add_errors.phpt
+++ b/ext/dom/tests/modern/token_list/add_errors.phpt
@@ -10,32 +10,32 @@

 try {
     $list->add("");
-} catch (DOMException $e) {
-    echo $e->getMessage(), "\n";
+} catch (Throwable $e) {
+    echo $e::class, ': ', $e->getMessage(), "\n";
 }
 try {
     $list->add("  ");
-} catch (DOMException $e) {
-    echo $e->getMessage(), "\n";
+} catch (Throwable $e) {
+    echo $e::class, ': ', $e->getMessage(), "\n";
 }
 try {
     $list->add("\0");
-} catch (ValueError $e) {
-    echo $e->getMessage(), "\n";
+} catch (Throwable $e) {
+    echo $e::class, ': ', $e->getMessage(), "\n";
 }
 try {
     $list->add(0);
-} catch (TypeError $e) {
-    echo $e->getMessage(), "\n";
+} catch (Throwable $e) {
+    echo $e::class, ': ', $e->getMessage(), "\n";
 }

 echo $dom->saveXML(), "\n";

 ?>
 --EXPECT--
-The empty string is not a valid token
-The token must not contain any ASCII whitespace
-Dom\TokenList::add(): Argument #1 must not contain any null bytes
-Dom\TokenList::add(): Argument #1 must be of type string, int given
+DOMException: The empty string is not a valid token
+DOMException: The token must not contain any ASCII whitespace
+ValueError: Dom\TokenList::add(): Argument #1 must not contain any null bytes
+TypeError: Dom\TokenList::add(): Argument #1 must be of type string, int given
 <?xml version="1.0" encoding="UTF-8"?>
 <root/>
diff --git a/ext/dom/tests/modern/token_list/contains_error.phpt b/ext/dom/tests/modern/token_list/contains_error.phpt
index 9f402e685f4..c2bc0865f7b 100644
--- a/ext/dom/tests/modern/token_list/contains_error.phpt
+++ b/ext/dom/tests/modern/token_list/contains_error.phpt
@@ -11,10 +11,10 @@

 try {
     $list->contains("\0");
-} catch (ValueError $e) {
-    echo $e->getMessage(), "\n";
+} catch (Throwable $e) {
+    echo $e::class, ': ', $e->getMessage(), "\n";
 }

 ?>
 --EXPECT--
-Dom\TokenList::contains(): Argument #1 ($token) must not contain any null bytes
+ValueError: Dom\TokenList::contains(): Argument #1 ($token) must not contain any null bytes
diff --git a/ext/dom/tests/modern/token_list/dimensions.phpt b/ext/dom/tests/modern/token_list/dimensions.phpt
index e1507d61b08..e012dfca7aa 100644
--- a/ext/dom/tests/modern/token_list/dimensions.phpt
+++ b/ext/dom/tests/modern/token_list/dimensions.phpt
@@ -19,8 +19,8 @@
 echo "--- \"foo\" ---\n";
 try {
     var_dump($list["foo"], isset($list["foo"]), empty($list["foo"]));
-} catch (TypeError $e) {
-    echo $e->getMessage(), "\n";
+} catch (Throwable $e) {
+    echo $e::class, ': ', $e->getMessage(), "\n";
 }

 echo "--- 1.1 ---\n";
@@ -68,7 +68,7 @@
 bool(true)
 bool(false)
 --- "foo" ---
-Cannot access offset of type string on Dom\TokenList
+TypeError: Cannot access offset of type string on Dom\TokenList
 --- 1.1 ---

 Deprecated: Implicit conversion from float 1.1 to int loses precision in %s on line %d
diff --git a/ext/dom/tests/modern/token_list/dimensions_error.phpt b/ext/dom/tests/modern/token_list/dimensions_error.phpt
index c29fc058ef9..d727a3f434e 100644
--- a/ext/dom/tests/modern/token_list/dimensions_error.phpt
+++ b/ext/dom/tests/modern/token_list/dimensions_error.phpt
@@ -17,41 +17,41 @@
 foreach ($testOffsets as $offset) {
     try {
         $list[$offset];
-    } catch (TypeError $e) {
-        echo $e->getMessage(), "\n";
+    } catch (Throwable $e) {
+        echo $e::class, ': ', $e->getMessage(), "\n";
     }

     try {
         isset($list[$offset]);
-    } catch (TypeError $e) {
-        echo $e->getMessage(), "\n";
+    } catch (Throwable $e) {
+        echo $e::class, ': ', $e->getMessage(), "\n";
     }

     try {
         empty($list[$offset]);
-    } catch (TypeError $e) {
-        echo $e->getMessage(), "\n";
+    } catch (Throwable $e) {
+        echo $e::class, ': ', $e->getMessage(), "\n";
     }
 }

 try {
     $list[][0] = 1;
-} catch (Error $e) {
-    echo $e->getMessage(), "\n";
+} catch (Throwable $e) {
+    echo $e::class, ': ', $e->getMessage(), "\n";
 }

 ?>
 --EXPECTF--
-Cannot access offset of type stdClass on Dom\TokenList
-Cannot access offset of type stdClass in isset or empty
-Cannot access offset of type stdClass in isset or empty
-Cannot access offset of type array on Dom\TokenList
-Cannot access offset of type array in isset or empty
-Cannot access offset of type array in isset or empty
+TypeError: Cannot access offset of type stdClass on Dom\TokenList
+TypeError: Cannot access offset of type stdClass in isset or empty
+TypeError: Cannot access offset of type stdClass in isset or empty
+TypeError: Cannot access offset of type array on Dom\TokenList
+TypeError: Cannot access offset of type array in isset or empty
+TypeError: Cannot access offset of type array in isset or empty

 Warning: Resource ID#%d used as offset, casting to integer (%d) in %s on line %d

 Warning: Resource ID#%d used as offset, casting to integer (%d) in %s on line %d

 Warning: Resource ID#%d used as offset, casting to integer (%d) in %s on line %d
-Cannot append to Dom\TokenList
+Error: Cannot append to Dom\TokenList
diff --git a/ext/dom/tests/modern/token_list/foreach_by_ref.phpt b/ext/dom/tests/modern/token_list/foreach_by_ref.phpt
index b13b4c51c7c..6a1d9f58a5c 100644
--- a/ext/dom/tests/modern/token_list/foreach_by_ref.phpt
+++ b/ext/dom/tests/modern/token_list/foreach_by_ref.phpt
@@ -10,10 +10,10 @@
 try {
     foreach ($dom->documentElement->classList as &$class) {
     }
-} catch (Error $e) {
-    echo $e->getMessage(), "\n";
+} catch (Throwable $e) {
+    echo $e::class, ': ', $e->getMessage(), "\n";
 }

 ?>
 --EXPECT--
-An iterator cannot be used with foreach by reference
+Error: An iterator cannot be used with foreach by reference
diff --git a/ext/dom/tests/modern/token_list/remove_errors.phpt b/ext/dom/tests/modern/token_list/remove_errors.phpt
index fe0e58c334c..e14bf249dd4 100644
--- a/ext/dom/tests/modern/token_list/remove_errors.phpt
+++ b/ext/dom/tests/modern/token_list/remove_errors.phpt
@@ -10,32 +10,32 @@

 try {
     $list->remove("");
-} catch (DOMException $e) {
-    echo $e->getMessage(), "\n";
+} catch (Throwable $e) {
+    echo $e::class, ': ', $e->getMessage(), "\n";
 }
 try {
     $list->remove("  ");
-} catch (DOMException $e) {
-    echo $e->getMessage(), "\n";
+} catch (Throwable $e) {
+    echo $e::class, ': ', $e->getMessage(), "\n";
 }
 try {
     $list->remove("\0");
-} catch (ValueError $e) {
-    echo $e->getMessage(), "\n";
+} catch (Throwable $e) {
+    echo $e::class, ': ', $e->getMessage(), "\n";
 }
 try {
     $list->remove(0);
-} catch (TypeError $e) {
-    echo $e->getMessage(), "\n";
+} catch (Throwable $e) {
+    echo $e::class, ': ', $e->getMessage(), "\n";
 }

 echo $dom->saveXML(), "\n";

 ?>
 --EXPECT--
-The empty string is not a valid token
-The token must not contain any ASCII whitespace
-Dom\TokenList::remove(): Argument #1 must not contain any null bytes
-Dom\TokenList::remove(): Argument #1 must be of type string, int given
+DOMException: The empty string is not a valid token
+DOMException: The token must not contain any ASCII whitespace
+ValueError: Dom\TokenList::remove(): Argument #1 must not contain any null bytes
+TypeError: Dom\TokenList::remove(): Argument #1 must be of type string, int given
 <?xml version="1.0" encoding="UTF-8"?>
 <root/>
diff --git a/ext/dom/tests/modern/token_list/replace_error.phpt b/ext/dom/tests/modern/token_list/replace_error.phpt
index 14b02373d57..21fce149b96 100644
--- a/ext/dom/tests/modern/token_list/replace_error.phpt
+++ b/ext/dom/tests/modern/token_list/replace_error.phpt
@@ -11,24 +11,24 @@

 try {
     $list->replace("\0", "X");
-} catch (ValueError $e) {
-    echo $e->getMessage(), "\n";
+} catch (Throwable $e) {
+    echo $e::class, ': ', $e->getMessage(), "\n";
 }

 try {
     $list->replace("X", "\0");
-} catch (ValueError $e) {
-    echo $e->getMessage(), "\n";
+} catch (Throwable $e) {
+    echo $e::class, ': ', $e->getMessage(), "\n";
 }

 try {
     $list->replace("a b", "X");
-} catch (DOMException $e) {
-    echo $e->getMessage(), "\n";
+} catch (Throwable $e) {
+    echo $e::class, ': ', $e->getMessage(), "\n";
 }

 ?>
 --EXPECT--
-Dom\TokenList::replace(): Argument #1 ($token) must not contain any null bytes
-Dom\TokenList::replace(): Argument #2 ($newToken) must not contain any null bytes
-The token must not contain any ASCII whitespace
+ValueError: Dom\TokenList::replace(): Argument #1 ($token) must not contain any null bytes
+ValueError: Dom\TokenList::replace(): Argument #2 ($newToken) must not contain any null bytes
+DOMException: The token must not contain any ASCII whitespace
diff --git a/ext/dom/tests/modern/token_list/supports.phpt b/ext/dom/tests/modern/token_list/supports.phpt
index 6fc1d7f2254..3c42a1190be 100644
--- a/ext/dom/tests/modern/token_list/supports.phpt
+++ b/ext/dom/tests/modern/token_list/supports.phpt
@@ -9,10 +9,10 @@
 $element = $dom->documentElement;
 try {
     $element->classList->supports('a');
-} catch (TypeError $e) {
-    echo $e->getMessage(), "\n";
+} catch (Throwable $e) {
+    echo $e::class, ': ', $e->getMessage(), "\n";
 }

 ?>
 --EXPECT--
-Attribute "class" does not define any supported tokens
+TypeError: Attribute "class" does not define any supported tokens
diff --git a/ext/dom/tests/modern/token_list/toggle_error.phpt b/ext/dom/tests/modern/token_list/toggle_error.phpt
index 7e3cfd46202..22ef1ed5eae 100644
--- a/ext/dom/tests/modern/token_list/toggle_error.phpt
+++ b/ext/dom/tests/modern/token_list/toggle_error.phpt
@@ -11,17 +11,17 @@

 try {
     $list->toggle("\0");
-} catch (ValueError $e) {
-    echo $e->getMessage(), "\n";
+} catch (Throwable $e) {
+    echo $e::class, ': ', $e->getMessage(), "\n";
 }

 try {
     $list->toggle("a b");
-} catch (DOMException $e) {
-    echo $e->getMessage(), "\n";
+} catch (Throwable $e) {
+    echo $e::class, ': ', $e->getMessage(), "\n";
 }

 ?>
 --EXPECT--
-Dom\TokenList::toggle(): Argument #1 ($token) must not contain any null bytes
-The token must not contain any ASCII whitespace
+ValueError: Dom\TokenList::toggle(): Argument #1 ($token) must not contain any null bytes
+DOMException: The token must not contain any ASCII whitespace
diff --git a/ext/dom/tests/modern/token_list/value_edge_cases.phpt b/ext/dom/tests/modern/token_list/value_edge_cases.phpt
index af32d84180b..ce030dad9f9 100644
--- a/ext/dom/tests/modern/token_list/value_edge_cases.phpt
+++ b/ext/dom/tests/modern/token_list/value_edge_cases.phpt
@@ -12,8 +12,8 @@

 try {
     $list->value = "\0";
-} catch (ValueError $e) {
-    echo $e->getMessage(), "\n";
+} catch (Throwable $e) {
+    echo $e::class, ': ', $e->getMessage(), "\n";
 }

 var_dump($list->value);
@@ -21,5 +21,5 @@
 ?>
 --EXPECT--
 string(0) ""
-Value must not contain any null bytes
+ValueError: Value must not contain any null bytes
 string(0) ""
diff --git a/ext/dom/tests/modern/xml/DtdNamedNodeMap_dimension_index_overflow_64.phpt b/ext/dom/tests/modern/xml/DtdNamedNodeMap_dimension_index_overflow_64.phpt
index cc2d7a06a2c..6ac1de9e955 100644
--- a/ext/dom/tests/modern/xml/DtdNamedNodeMap_dimension_index_overflow_64.phpt
+++ b/ext/dom/tests/modern/xml/DtdNamedNodeMap_dimension_index_overflow_64.phpt
@@ -23,8 +23,8 @@
 function dump_access(Closure $callback): void {
     try {
         var_dump($callback()?->nodeName);
-    } catch (ValueError $e) {
-        echo $e->getMessage(), PHP_EOL;
+    } catch (Throwable $e) {
+        echo $e::class, ': ', $e->getMessage(), "\n";
     }
 }

@@ -36,6 +36,6 @@ function dump_access(Closure $callback): void {
 ?>
 --EXPECT--
 NULL
-must be between 0 and 2147483647
+ValueError: must be between 0 and 2147483647
 NULL
-must be between 0 and 2147483647
+ValueError: must be between 0 and 2147483647
diff --git a/ext/dom/tests/modern/xml/Element_innerHTML_writing_errors.phpt b/ext/dom/tests/modern/xml/Element_innerHTML_writing_errors.phpt
index 0316ac88439..53d61facc6b 100644
--- a/ext/dom/tests/modern/xml/Element_innerHTML_writing_errors.phpt
+++ b/ext/dom/tests/modern/xml/Element_innerHTML_writing_errors.phpt
@@ -18,8 +18,8 @@ function test($child, $html) {
     global $dom, $original;
     try {
         $child->innerHTML = $html;
-    } catch (DOMException $e) {
-        echo $e->getMessage(), "\n";
+    } catch (Throwable $e) {
+        echo $e::class, ': ', $e->getMessage(), "\n";
     }
     var_dump($dom->saveXML() === $original);
 }
@@ -33,15 +33,15 @@ function test($child, $html) {

 ?>
 --EXPECT--
-XML fragment is not well-formed
+DOMException: XML fragment is not well-formed
 bool(true)
-XML fragment is not well-formed
+DOMException: XML fragment is not well-formed
 bool(true)
-XML fragment is not well-formed
+DOMException: XML fragment is not well-formed
 bool(true)
-XML fragment is not well-formed
+DOMException: XML fragment is not well-formed
 bool(true)
-XML fragment is not well-formed
+DOMException: XML fragment is not well-formed
 bool(true)
-XML fragment is not well-formed
+DOMException: XML fragment is not well-formed
 bool(true)
diff --git a/ext/dom/tests/modern/xml/Element_innerOuterHTML_reading_errors.phpt b/ext/dom/tests/modern/xml/Element_innerOuterHTML_reading_errors.phpt
index 585c9c5fd87..9e71a18caf0 100644
--- a/ext/dom/tests/modern/xml/Element_innerOuterHTML_reading_errors.phpt
+++ b/ext/dom/tests/modern/xml/Element_innerOuterHTML_reading_errors.phpt
@@ -16,13 +16,13 @@ function createContainer() {
 function test($container) {
     try {
         var_dump($container->innerHTML);
-    } catch (DOMException $e) {
-        echo $e->getMessage(), "\n";
+    } catch (Throwable $e) {
+        echo $e::class, ': ', $e->getMessage(), "\n";
     }
     try {
         var_dump($container->outerHTML);
-    } catch (DOMException $e) {
-        echo $e->getMessage(), "\n";
+    } catch (Throwable $e) {
+        echo $e::class, ': ', $e->getMessage(), "\n";
     }
 }

@@ -96,33 +96,33 @@ function test($container) {

 ?>
 --EXPECT--
-The resulting XML serialization is not well-formed
-The resulting XML serialization is not well-formed
-The resulting XML serialization is not well-formed
-The resulting XML serialization is not well-formed
-The resulting XML serialization is not well-formed
-The resulting XML serialization is not well-formed
-The resulting XML serialization is not well-formed
-The resulting XML serialization is not well-formed
-The resulting XML serialization is not well-formed
-The resulting XML serialization is not well-formed
-The resulting XML serialization is not well-formed
-The resulting XML serialization is not well-formed
-The resulting XML serialization is not well-formed
-The resulting XML serialization is not well-formed
-The resulting XML serialization is not well-formed
-The resulting XML serialization is not well-formed
-The resulting XML serialization is not well-formed
-The resulting XML serialization is not well-formed
-The resulting XML serialization is not well-formed
-The resulting XML serialization is not well-formed
-The resulting XML serialization is not well-formed
-The resulting XML serialization is not well-formed
-The resulting XML serialization is not well-formed
-The resulting XML serialization is not well-formed
-The resulting XML serialization is not well-formed
-The resulting XML serialization is not well-formed
-The resulting XML serialization is not well-formed
-The resulting XML serialization is not well-formed
-The resulting XML serialization is not well-formed
-The resulting XML serialization is not well-formed
+DOMException: The resulting XML serialization is not well-formed
+DOMException: The resulting XML serialization is not well-formed
+DOMException: The resulting XML serialization is not well-formed
+DOMException: The resulting XML serialization is not well-formed
+DOMException: The resulting XML serialization is not well-formed
+DOMException: The resulting XML serialization is not well-formed
+DOMException: The resulting XML serialization is not well-formed
+DOMException: The resulting XML serialization is not well-formed
+DOMException: The resulting XML serialization is not well-formed
+DOMException: The resulting XML serialization is not well-formed
+DOMException: The resulting XML serialization is not well-formed
+DOMException: The resulting XML serialization is not well-formed
+DOMException: The resulting XML serialization is not well-formed
+DOMException: The resulting XML serialization is not well-formed
+DOMException: The resulting XML serialization is not well-formed
+DOMException: The resulting XML serialization is not well-formed
+DOMException: The resulting XML serialization is not well-formed
+DOMException: The resulting XML serialization is not well-formed
+DOMException: The resulting XML serialization is not well-formed
+DOMException: The resulting XML serialization is not well-formed
+DOMException: The resulting XML serialization is not well-formed
+DOMException: The resulting XML serialization is not well-formed
+DOMException: The resulting XML serialization is not well-formed
+DOMException: The resulting XML serialization is not well-formed
+DOMException: The resulting XML serialization is not well-formed
+DOMException: The resulting XML serialization is not well-formed
+DOMException: The resulting XML serialization is not well-formed
+DOMException: The resulting XML serialization is not well-formed
+DOMException: The resulting XML serialization is not well-formed
+DOMException: The resulting XML serialization is not well-formed
diff --git a/ext/dom/tests/modern/xml/Element_insertAdjacentHTML_errors.phpt b/ext/dom/tests/modern/xml/Element_insertAdjacentHTML_errors.phpt
index 0ecd1d48736..2f056375b51 100644
--- a/ext/dom/tests/modern/xml/Element_insertAdjacentHTML_errors.phpt
+++ b/ext/dom/tests/modern/xml/Element_insertAdjacentHTML_errors.phpt
@@ -8,10 +8,10 @@
 $dom = Dom\XMLDocument::createFromString('<root/>');
 try {
     $dom->documentElement->insertAdjacentHTML(Dom\AdjacentPosition::AfterBegin, "<non-well-formed>");
-} catch (DOMException $e) {
-    echo $e->getMessage(), "\n";
+} catch (Throwable $e) {
+    echo $e::class, ': ', $e->getMessage(), "\n";
 }

 ?>
 --EXPECT--
-XML fragment is not well-formed
+DOMException: XML fragment is not well-formed
diff --git a/ext/dom/tests/modern/xml/Element_outerHTML_writing_errors.phpt b/ext/dom/tests/modern/xml/Element_outerHTML_writing_errors.phpt
index f7602539aca..bdcbfafcced 100644
--- a/ext/dom/tests/modern/xml/Element_outerHTML_writing_errors.phpt
+++ b/ext/dom/tests/modern/xml/Element_outerHTML_writing_errors.phpt
@@ -8,18 +8,18 @@
 $dom = Dom\XMLDocument::createFromString('<root/>');
 try {
     $dom->documentElement->outerHTML = '<x/>';
-} catch (DOMException $e) {
-    echo $e->getMessage(), "\n";
+} catch (Throwable $e) {
+    echo $e::class, ': ', $e->getMessage(), "\n";
 }

 $dom = Dom\XMLDocument::createFromString('<root><child/></root>');
 try {
     $dom->documentElement->firstChild->outerHTML = '<!DOCTYPE html>';
-} catch (DOMException $e) {
-    echo $e->getMessage(), "\n";
+} catch (Throwable $e) {
+    echo $e::class, ': ', $e->getMessage(), "\n";
 }

 ?>
 --EXPECT--
-Invalid Modification Error
-XML fragment is not well-formed
+DOMException: Invalid Modification Error
+DOMException: XML fragment is not well-formed
diff --git a/ext/dom/tests/modern/xml/Node_removeChild_from_comment.phpt b/ext/dom/tests/modern/xml/Node_removeChild_from_comment.phpt
index eae3c97dbf0..37ec160ce0d 100644
--- a/ext/dom/tests/modern/xml/Node_removeChild_from_comment.phpt
+++ b/ext/dom/tests/modern/xml/Node_removeChild_from_comment.phpt
@@ -11,10 +11,10 @@

 try {
     $comment->removeChild($child);
-} catch (DOMException $e) {
-    echo $e->getMessage(), "\n";
+} catch (Throwable $e) {
+    echo $e::class, ': ', $e->getMessage(), "\n";
 }

 ?>
 --EXPECT--
-Not Found Error
+DOMException: Not Found Error
diff --git a/ext/dom/tests/modern/xml/XMLDocument_createFromFile_override_encoding.phpt b/ext/dom/tests/modern/xml/XMLDocument_createFromFile_override_encoding.phpt
index f48c5f7f5a1..74b6da07637 100644
--- a/ext/dom/tests/modern/xml/XMLDocument_createFromFile_override_encoding.phpt
+++ b/ext/dom/tests/modern/xml/XMLDocument_createFromFile_override_encoding.phpt
@@ -7,8 +7,8 @@

 try {
     Dom\XMLDocument::createFromFile(__DIR__ . '/dummy.xml', overrideEncoding: 'nonexistent');
-} catch (ValueError $e) {
-    echo $e->getMessage(), "\n";
+} catch (Throwable $e) {
+    echo $e::class, ': ', $e->getMessage(), "\n";
 }

 // The override encoding matches with the document encoding attribute
@@ -23,7 +23,7 @@

 ?>
 --EXPECT--
-Dom\XMLDocument::createFromFile(): Argument #3 ($overrideEncoding) must be a valid document encoding
+ValueError: Dom\XMLDocument::createFromFile(): Argument #3 ($overrideEncoding) must be a valid document encoding
 string(2) "é"
 string(5) "UTF-8"
 string(4) "é"
diff --git a/ext/dom/tests/modern/xml/XMLDocument_createFromString_override_encoding.phpt b/ext/dom/tests/modern/xml/XMLDocument_createFromString_override_encoding.phpt
index e45f74847dd..add2a8cdd08 100644
--- a/ext/dom/tests/modern/xml/XMLDocument_createFromString_override_encoding.phpt
+++ b/ext/dom/tests/modern/xml/XMLDocument_createFromString_override_encoding.phpt
@@ -7,8 +7,8 @@

 try {
     Dom\XMLDocument::createFromString(file_get_contents(__DIR__ . '/dummy.xml'), overrideEncoding: 'nonexistent');
-} catch (ValueError $e) {
-    echo $e->getMessage(), "\n";
+} catch (Throwable $e) {
+    echo $e::class, ': ', $e->getMessage(), "\n";
 }

 // The override encoding matches with the document encoding attribute
@@ -23,7 +23,7 @@

 ?>
 --EXPECT--
-Dom\XMLDocument::createFromString(): Argument #3 ($overrideEncoding) must be a valid document encoding
+ValueError: Dom\XMLDocument::createFromString(): Argument #3 ($overrideEncoding) must be a valid document encoding
 string(2) "é"
 string(5) "UTF-8"
 string(4) "é"
diff --git a/ext/dom/tests/modern/xml/XMLDocument_fromFile_03.phpt b/ext/dom/tests/modern/xml/XMLDocument_fromFile_03.phpt
index 73c1b0d2235..8ced79db210 100644
--- a/ext/dom/tests/modern/xml/XMLDocument_fromFile_03.phpt
+++ b/ext/dom/tests/modern/xml/XMLDocument_fromFile_03.phpt
@@ -7,10 +7,10 @@

 try {
     Dom\XMLDocument::createFromFile("%00");
-} catch (ValueError $e) {
-    echo $e->getMessage();
+} catch (Throwable $e) {
+    echo $e::class, ': ', $e->getMessage(), "\n";
 }

 ?>
 --EXPECT--
-Dom\XMLDocument::createFromFile(): Argument #1 ($path) must not contain percent-encoded NUL bytes
+ValueError: Dom\XMLDocument::createFromFile(): Argument #1 ($path) must not contain percent-encoded NUL bytes
diff --git a/ext/dom/tests/modern/xml/XMLDocument_fromString_03.phpt b/ext/dom/tests/modern/xml/XMLDocument_fromString_03.phpt
index 16db09547bf..d56b6ad4685 100644
--- a/ext/dom/tests/modern/xml/XMLDocument_fromString_03.phpt
+++ b/ext/dom/tests/modern/xml/XMLDocument_fromString_03.phpt
@@ -11,8 +11,8 @@

 try {
     Dom\XMLDocument::createFromString('<?xml version="1.0"?><container/>', -1);
-} catch (ValueError $e) {
-    echo $e->getMessage(), "\n";
+} catch (Throwable $e) {
+    echo $e::class, ': ', $e->getMessage(), "\n";
 }

 foreach ($flags as $flag) {
@@ -21,7 +21,7 @@

 ?>
 --EXPECTF--
-Dom\XMLDocument::createFromString(): Argument #2 ($options) contains invalid flags (allowed flags: %s)
+ValueError: Dom\XMLDocument::createFromString(): Argument #2 ($options) contains invalid flags (allowed flags: %s)
 bool(true)
 bool(true)
 bool(true)
diff --git a/ext/dom/tests/modern/xml/XMLDocument_xpath.phpt b/ext/dom/tests/modern/xml/XMLDocument_xpath.phpt
index b42c21ed9ab..bd8b1519683 100644
--- a/ext/dom/tests/modern/xml/XMLDocument_xpath.phpt
+++ b/ext/dom/tests/modern/xml/XMLDocument_xpath.phpt
@@ -45,8 +45,8 @@
 // Namespace nodes don't exist in modern day DOM.
 try {
     var_dump($xpath->evaluate("//*/namespace::*"));
-} catch (DOMException $e) {
-    echo $e->getCode(), ": ", $e->getMessage(), "\n";
+} catch (Throwable $e) {
+    echo $e::class, ': ', $e->getCode(), ': ', $e->getMessage(), "\n";
 }

 ?>
@@ -71,4 +71,4 @@
 string(11) "Dom\Comment"
 string(9) " comment "
 --- Get a namespace node ---
-9: The namespace axis is not well-defined in the living DOM specification. Use Dom\Element::getInScopeNamespaces() or Dom\Element::getDescendantNamespaces() instead.
+DOMException: 9: The namespace axis is not well-defined in the living DOM specification. Use Dom\Element::getInScopeNamespaces() or Dom\Element::getDescendantNamespaces() instead.
diff --git a/ext/dom/tests/modern/xml/XMLDocument_xpath_errors.phpt b/ext/dom/tests/modern/xml/XMLDocument_xpath_errors.phpt
index 1ef52b50961..4d0a908c8fc 100644
--- a/ext/dom/tests/modern/xml/XMLDocument_xpath_errors.phpt
+++ b/ext/dom/tests/modern/xml/XMLDocument_xpath_errors.phpt
@@ -11,11 +11,11 @@

 try {
     var_dump($xpath->evaluate('-'));
-} catch (Error $e) {
-    var_dump($e->getMessage());
+} catch (Throwable $e) {
+    echo $e::class, ': ', $e->getMessage(), "\n";
 }

 ?>
 --EXPECTF--
 Warning: Dom\XPath::evaluate(): Invalid expression in %s on line %d
-string(35) "Could not evaluate XPath expression"
+Error: Could not evaluate XPath expression
diff --git a/ext/dom/tests/modern/xml/canonicalize_unattached.phpt b/ext/dom/tests/modern/xml/canonicalize_unattached.phpt
index cec5f108575..e5d4bb7e9d0 100644
--- a/ext/dom/tests/modern/xml/canonicalize_unattached.phpt
+++ b/ext/dom/tests/modern/xml/canonicalize_unattached.phpt
@@ -11,10 +11,10 @@

 try {
     $child->C14N();
-} catch (Dom\DOMException $e) {
-    echo $e->getMessage(), "\n";
+} catch (Throwable $e) {
+    echo $e::class, ': ', $e->getMessage(), "\n";
 }

 ?>
 --EXPECT--
-Canonicalization can only happen on nodes attached to a document.
+DOMException: Canonicalization can only happen on nodes attached to a document.
diff --git a/ext/dom/tests/modern/xml/serialize_empty_xmlns.phpt b/ext/dom/tests/modern/xml/serialize_empty_xmlns.phpt
index 7770143b224..9de8f4007d4 100644
--- a/ext/dom/tests/modern/xml/serialize_empty_xmlns.phpt
+++ b/ext/dom/tests/modern/xml/serialize_empty_xmlns.phpt
@@ -15,11 +15,11 @@
 $x->setAttributeNS('http://www.w3.org/2000/xmlns/', 'xmlns:a', '');
 try {
     var_dump($dom->documentElement->innerHTML);
-} catch (DOMException $e) {
-    echo $e->getMessage(), "\n";
+} catch (Throwable $e) {
+    echo $e::class, ': ', $e->getMessage(), "\n";
 }

 ?>
 --EXPECT--
 string(13) "<x xmlns=""/>"
-The resulting XML serialization is not well-formed
+DOMException: The resulting XML serialization is not well-formed
diff --git a/ext/dom/tests/modern/xml/simplexml_interop.phpt b/ext/dom/tests/modern/xml/simplexml_interop.phpt
index a1b02b7bdd8..52c2b61ae45 100644
--- a/ext/dom/tests/modern/xml/simplexml_interop.phpt
+++ b/ext/dom/tests/modern/xml/simplexml_interop.phpt
@@ -21,8 +21,8 @@
 // This should fail because it has been imported already above in modern DOM
 try {
     dom_import_simplexml($sxe);
-} catch (TypeError $e) {
-    echo $e->getMessage(), "\n";
+} catch (Throwable $e) {
+    echo $e::class, ': ', $e->getMessage(), "\n";
 }

 // Import again and compare
@@ -37,5 +37,5 @@
 <container xmlns="urn:a">foo</container>
 <container xmlns="urn:a">foo<child/></container>
 <container xmlns="urn:a">foo<child/><name>value</name></container>
-dom_import_simplexml(): Argument #1 ($node) must not be already imported as a Dom\Node
+TypeError: dom_import_simplexml(): Argument #1 ($node) must not be already imported as a Dom\Node
 bool(true)
diff --git a/ext/dom/tests/not_serializable.phpt b/ext/dom/tests/not_serializable.phpt
index 36053070f40..82bf2d4ad53 100644
--- a/ext/dom/tests/not_serializable.phpt
+++ b/ext/dom/tests/not_serializable.phpt
@@ -9,49 +9,49 @@
 $doc->loadXML('<root><node/></root>');
 try {
     serialize($doc);
-} catch (Exception $e) {
-    echo $e->getMessage(), "\n";
+} catch (Throwable $e) {
+    echo $e::class, ': ', $e->getMessage(), "\n";
 }

 $node = $doc->documentElement;
 try {
     serialize($node);
-} catch (Exception $e) {
-    echo $e->getMessage(), "\n";
+} catch (Throwable $e) {
+    echo $e::class, ': ', $e->getMessage(), "\n";
 }

 $xpath = new DOMXPath($doc);
 try {
     serialize($xpath);
-} catch (Exception $e) {
-    echo $e->getMessage(), "\n";
+} catch (Throwable $e) {
+    echo $e::class, ': ', $e->getMessage(), "\n";
 }

 $ns = $xpath->query('//namespace::*')->item(0);
 try {
     serialize($ns);
-} catch (Exception $e) {
-    echo $e->getMessage(), "\n";
+} catch (Throwable $e) {
+    echo $e::class, ': ', $e->getMessage(), "\n";
 }

 $dom = Dom\XMLDocument::createEmpty();
 try {
     serialize($dom);
-} catch (Exception $e) {
-    echo $e->getMessage(), "\n";
+} catch (Throwable $e) {
+    echo $e::class, ': ', $e->getMessage(), "\n";
 }

 try {
     serialize(new Dom\XPath($dom));
-} catch (Exception $e) {
-    echo $e->getMessage(), "\n";
+} catch (Throwable $e) {
+    echo $e::class, ': ', $e->getMessage(), "\n";
 }

 ?>
 --EXPECT--
-Serialization of 'DOMDocument' is not allowed, unless serialization methods are implemented in a subclass
-Serialization of 'DOMElement' is not allowed, unless serialization methods are implemented in a subclass
-Serialization of 'DOMXPath' is not allowed
-Serialization of 'DOMNameSpaceNode' is not allowed, unless serialization methods are implemented in a subclass
-Serialization of 'Dom\XMLDocument' is not allowed, unless serialization methods are implemented in a subclass
-Serialization of 'Dom\XPath' is not allowed
+Exception: Serialization of 'DOMDocument' is not allowed, unless serialization methods are implemented in a subclass
+Exception: Serialization of 'DOMElement' is not allowed, unless serialization methods are implemented in a subclass
+Exception: Serialization of 'DOMXPath' is not allowed
+Exception: Serialization of 'DOMNameSpaceNode' is not allowed, unless serialization methods are implemented in a subclass
+Exception: Serialization of 'Dom\XMLDocument' is not allowed, unless serialization methods are implemented in a subclass
+Exception: Serialization of 'Dom\XPath' is not allowed
diff --git a/ext/dom/tests/not_unserializable.phpt b/ext/dom/tests/not_unserializable.phpt
index a25a2737e85..8b3d2ce695c 100644
--- a/ext/dom/tests/not_unserializable.phpt
+++ b/ext/dom/tests/not_unserializable.phpt
@@ -16,14 +16,14 @@
 {
     try {
         unserialize('O:' . strlen($class) . ':"' . $class . '":0:{}');
-    } catch (Exception $e) {
-        echo $e->getMessage(), "\n";
+    } catch (Throwable $e) {
+        echo $e::class, ': ', $e->getMessage(), "\n";
     }
 }

 ?>
 --EXPECT--
-Unserialization of 'DOMXPath' is not allowed
-Unserialization of 'DOMDocument' is not allowed, unless unserialization methods are implemented in a subclass
-Unserialization of 'DOMNode' is not allowed, unless unserialization methods are implemented in a subclass
-Unserialization of 'DOMNameSpaceNode' is not allowed, unless unserialization methods are implemented in a subclass
+Exception: Unserialization of 'DOMXPath' is not allowed
+Exception: Unserialization of 'DOMDocument' is not allowed, unless unserialization methods are implemented in a subclass
+Exception: Unserialization of 'DOMNode' is not allowed, unless unserialization methods are implemented in a subclass
+Exception: Unserialization of 'DOMNameSpaceNode' is not allowed, unless unserialization methods are implemented in a subclass
diff --git a/ext/dom/tests/null_text_content_manipulation.phpt b/ext/dom/tests/null_text_content_manipulation.phpt
index 9b1e35d60f7..12e18ac7406 100644
--- a/ext/dom/tests/null_text_content_manipulation.phpt
+++ b/ext/dom/tests/null_text_content_manipulation.phpt
@@ -7,27 +7,27 @@
 $text = new DOMText();
 try {
     var_dump($text->substringData(1, 0));
-} catch (DOMException $e) {
-    echo $e->getMessage(), "\n";
+} catch (Throwable $e) {
+    echo $e::class, ': ', $e->getMessage(), "\n";
 }
 try {
     var_dump($text->insertData(1, ""));
-} catch (DOMException $e) {
-    echo $e->getMessage(), "\n";
+} catch (Throwable $e) {
+    echo $e::class, ': ', $e->getMessage(), "\n";
 }
 try {
     var_dump($text->deleteData(1, 1));
-} catch (DOMException $e) {
-    echo $e->getMessage(), "\n";
+} catch (Throwable $e) {
+    echo $e::class, ': ', $e->getMessage(), "\n";
 }
 try {
     var_dump($text->replaceData(1, 1, ""));
-} catch (DOMException $e) {
-    echo $e->getMessage(), "\n";
+} catch (Throwable $e) {
+    echo $e::class, ': ', $e->getMessage(), "\n";
 }
 ?>
 --EXPECT--
-Index Size Error
-Index Size Error
-Index Size Error
-Index Size Error
+DOMException: Index Size Error
+DOMException: Index Size Error
+DOMException: Index Size Error
+DOMException: Index Size Error
diff --git a/ext/dom/tests/php_function_edge_cases.phpt b/ext/dom/tests/php_function_edge_cases.phpt
index 1091b50ce19..9be75918ec3 100644
--- a/ext/dom/tests/php_function_edge_cases.phpt
+++ b/ext/dom/tests/php_function_edge_cases.phpt
@@ -12,16 +12,16 @@
 $xpath->registerPHPFunctions();
 try {
     $xpath->query("//a[php:function(3)]");
-} catch (TypeError $e) {
-    echo $e->getMessage(), "\n";
+} catch (Throwable $e) {
+    echo $e::class, ': ', $e->getMessage(), "\n";
 }
 try {
     $xpath->query("//a[php:function()]");
 } catch (Throwable $e) {
-    echo $e->getMessage(), "\n";
+    echo $e::class, ': ', $e->getMessage(), "\n";
 }

 ?>
 --EXPECT--
-Handler name must be a string
-Function name must be passed as the first argument
+TypeError: Handler name must be a string
+Error: Function name must be passed as the first argument
diff --git a/ext/dom/tests/property_write_errors.phpt b/ext/dom/tests/property_write_errors.phpt
index 7d2af3b1055..0459f10b8fe 100644
--- a/ext/dom/tests/property_write_errors.phpt
+++ b/ext/dom/tests/property_write_errors.phpt
@@ -10,47 +10,47 @@

 try {
     $dom->nodeValue = [];
-} catch (TypeError $exception) {
-    echo $exception->getMessage() . "\n";
+} catch (Throwable $exception) {
+    echo $exception::class, ': ', $exception->getMessage(), "\n";
 }

 try {
     $dom->nodeType += 1;
-} catch (Error $exception) {
-    echo $exception->getMessage() . "\n";
+} catch (Throwable $exception) {
+    echo $exception::class, ': ', $exception->getMessage(), "\n";
 }

 try {
     $dom->xmlEncoding = null;
-} catch (Error $exception) {
-    echo $exception->getMessage() . "\n";
+} catch (Throwable $exception) {
+    echo $exception::class, ': ', $exception->getMessage(), "\n";
 }

 $entity = new DOMEntity();

 try {
     $entity->actualEncoding = null;
-} catch (Error $exception) {
-    echo $exception->getMessage() . "\n";
+} catch (Throwable $exception) {
+    echo $exception::class, ': ', $exception->getMessage(), "\n";
 }

 try {
     $entity->encoding = null;
-} catch (Error $exception) {
-    echo $exception->getMessage() . "\n";
+} catch (Throwable $exception) {
+    echo $exception::class, ': ', $exception->getMessage(), "\n";
 }

 try {
     $entity->version = null;
-} catch (Error $exception) {
-    echo $exception->getMessage() . "\n";
+} catch (Throwable $exception) {
+    echo $exception::class, ': ', $exception->getMessage(), "\n";
 }

 ?>
 --EXPECT--
-Cannot assign array to property DOMNode::$nodeValue of type ?string
-Cannot modify private(set) property DOMNode::$nodeType from global scope
-Cannot modify private(set) property DOMDocument::$xmlEncoding from global scope
-Cannot modify private(set) property DOMEntity::$actualEncoding from global scope
-Cannot modify private(set) property DOMEntity::$encoding from global scope
-Cannot modify private(set) property DOMEntity::$version from global scope
+TypeError: Cannot assign array to property DOMNode::$nodeValue of type ?string
+Error: Cannot modify private(set) property DOMNode::$nodeType from global scope
+Error: Cannot modify private(set) property DOMDocument::$xmlEncoding from global scope
+Error: Cannot modify private(set) property DOMEntity::$actualEncoding from global scope
+Error: Cannot modify private(set) property DOMEntity::$encoding from global scope
+Error: Cannot modify private(set) property DOMEntity::$version from global scope
diff --git a/ext/dom/tests/registerNodeClass_abstract_class.phpt b/ext/dom/tests/registerNodeClass_abstract_class.phpt
index 24124d712ea..e83643702c3 100644
--- a/ext/dom/tests/registerNodeClass_abstract_class.phpt
+++ b/ext/dom/tests/registerNodeClass_abstract_class.phpt
@@ -13,8 +13,8 @@ abstract function foo();

 try {
     $dom->registerNodeClass("DOMElement", "Test");
-} catch (ValueError $e) {
-    echo "ValueError: ", $e->getMessage(), "\n";
+} catch (Throwable $e) {
+    echo $e::class, ': ', $e->getMessage(), "\n";
 }

 $dom->createElement("foo");
diff --git a/ext/dom/tests/registerPhpFunctionNS_errors.phpt b/ext/dom/tests/registerPhpFunctionNS_errors.phpt
index 5098d8f7a84..e366b58d3dd 100644
--- a/ext/dom/tests/registerPhpFunctionNS_errors.phpt
+++ b/ext/dom/tests/registerPhpFunctionNS_errors.phpt
@@ -17,45 +17,45 @@ public function __call($name, $args) {

 try {
     $xpath->registerPhpFunctionNS('http://php.net/xpath', 'strtolower', strtolower(...));
-} catch (ValueError $e) {
-    echo $e->getMessage(), "\n";
+} catch (Throwable $e) {
+    echo $e::class, ': ', $e->getMessage(), "\n";
 }

 try {
     $xpath->registerPhpFunctionNS('http://php.net/xpath', 'test', [new TrampolineClass, 'test']);
-} catch (ValueError $e) {
-    echo $e->getMessage(), "\n";
+} catch (Throwable $e) {
+    echo $e::class, ': ', $e->getMessage(), "\n";
 }

 try {
     $xpath->registerPhpFunctionNS('urn:foo', '$$$', [new TrampolineClass, 'test']);
-} catch (ValueError $e) {
-    echo $e->getMessage(), "\n";
+} catch (Throwable $e) {
+    echo $e::class, ': ', $e->getMessage(), "\n";
 }

 try {
     $xpath->registerPhpFunctionNS('urn:foo', 'x:a', strtolower(...));
-} catch (ValueError $e) {
-    echo $e->getMessage(), "\n";
+} catch (Throwable $e) {
+    echo $e::class, ': ', $e->getMessage(), "\n";
 }

 try {
     $xpath->registerPhpFunctionNS("urn:foo", "\0", strtolower(...));
-} catch (ValueError $e) {
-    echo $e->getMessage(), "\n";
+} catch (Throwable $e) {
+    echo $e::class, ': ', $e->getMessage(), "\n";
 }

 try {
     $xpath->registerPhpFunctionNS("\0", 'strtolower', strtolower(...));
-} catch (ValueError $e) {
-    echo $e->getMessage(), "\n";
+} catch (Throwable $e) {
+    echo $e::class, ': ', $e->getMessage(), "\n";
 }

 ?>
 --EXPECT--
-DOMXPath::registerPhpFunctionNS(): Argument #1 ($namespaceURI) must not be "http://php.net/xpath" because it is reserved by PHP
-DOMXPath::registerPhpFunctionNS(): Argument #1 ($namespaceURI) must not be "http://php.net/xpath" because it is reserved by PHP
-DOMXPath::registerPhpFunctionNS(): Argument #2 ($name) must be a valid callback name
-DOMXPath::registerPhpFunctionNS(): Argument #2 ($name) must be a valid callback name
-DOMXPath::registerPhpFunctionNS(): Argument #2 ($name) must not contain any null bytes
-DOMXPath::registerPhpFunctionNS(): Argument #1 ($namespaceURI) must not contain any null bytes
+ValueError: DOMXPath::registerPhpFunctionNS(): Argument #1 ($namespaceURI) must not be "http://php.net/xpath" because it is reserved by PHP
+ValueError: DOMXPath::registerPhpFunctionNS(): Argument #1 ($namespaceURI) must not be "http://php.net/xpath" because it is reserved by PHP
+ValueError: DOMXPath::registerPhpFunctionNS(): Argument #2 ($name) must be a valid callback name
+ValueError: DOMXPath::registerPhpFunctionNS(): Argument #2 ($name) must be a valid callback name
+ValueError: DOMXPath::registerPhpFunctionNS(): Argument #2 ($name) must not contain any null bytes
+ValueError: DOMXPath::registerPhpFunctionNS(): Argument #1 ($namespaceURI) must not contain any null bytes
diff --git a/ext/dom/tests/register_node_class.phpt b/ext/dom/tests/register_node_class.phpt
index 7482ec27bfa..0ceddc6b493 100644
--- a/ext/dom/tests/register_node_class.phpt
+++ b/ext/dom/tests/register_node_class.phpt
@@ -29,8 +29,8 @@ function testit() { return "HELLO Element"; }
 echo get_class($attr), "\n";
 try {
     print $attr->testit()."\n";
-} catch (Error $e) {
-    echo $e->getMessage();
+} catch (Throwable $e) {
+    echo $e::class, ': ', $e->getMessage(), "\n";
 }
 ?>
 --EXPECT--
@@ -39,4 +39,4 @@ function testit() { return "HELLO Element"; }
 myAttribute
 HELLO Attribute
 DOMAttr
-Call to undefined method DOMAttr::testit()
+Error: Call to undefined method DOMAttr::testit()
diff --git a/ext/dom/tests/replaceChild_attribute_validation.phpt b/ext/dom/tests/replaceChild_attribute_validation.phpt
index 32d5990f75e..420b06b7859 100644
--- a/ext/dom/tests/replaceChild_attribute_validation.phpt
+++ b/ext/dom/tests/replaceChild_attribute_validation.phpt
@@ -11,8 +11,8 @@

 try {
     $attr->replaceChild($dom->createProcessingInstruction('pi'), $attr->firstChild);
-} catch (DOMException $e) {
-    echo $e->getMessage(), "\n";
+} catch (Throwable $e) {
+    echo $e::class, ': ', $e->getMessage(), "\n";
 }

 $root = $dom->appendChild($dom->createElement('root'));
@@ -22,6 +22,6 @@

 ?>
 --EXPECT--
-Hierarchy Request Error
+DOMException: Hierarchy Request Error
 <?xml version="1.0"?>
 <root attr="test"/>
diff --git a/ext/dom/tests/unsetting_properties.phpt b/ext/dom/tests/unsetting_properties.phpt
index ec309c18bf5..69fe50112bc 100644
--- a/ext/dom/tests/unsetting_properties.phpt
+++ b/ext/dom/tests/unsetting_properties.phpt
@@ -17,16 +17,16 @@ class MyElement extends DOMElement {
 unset($root->myProp);
 try {
     $root->myProp;
-} catch (Error $e) {
-    echo $e->getMessage(), "\n";
+} catch (Throwable $e) {
+    echo $e::class, ': ', $e->getMessage(), "\n";
 }
 try {
     unset($root->textContent);
-} catch (Error $e) {
-    echo $e->getMessage(), "\n";
+} catch (Throwable $e) {
+    echo $e::class, ': ', $e->getMessage(), "\n";
 }

 ?>
 --EXPECT--
-Typed property MyElement::$myProp must not be accessed before initialization
-Cannot unset MyElement::$textContent
+Error: Typed property MyElement::$myProp must not be accessed before initialization
+Error: Cannot unset MyElement::$textContent
diff --git a/ext/dom/tests/xpath_domnamespacenode_advanced.phpt b/ext/dom/tests/xpath_domnamespacenode_advanced.phpt
index bbc49dc5465..21ba3ab8df6 100644
--- a/ext/dom/tests/xpath_domnamespacenode_advanced.phpt
+++ b/ext/dom/tests/xpath_domnamespacenode_advanced.phpt
@@ -29,8 +29,8 @@
     // Second & third attempt should fail because it's no longer in the document
     try {
         $attribute->parentNode->remove();
-    } catch (\DOMException $e) {
-        echo $e->getMessage(), "\n";
+    } catch (\Throwable $e) {
+        echo $e::class, ': ', $e->getMessage(), "\n";
     }
     // However, it should not cause a use-after-free
     echo "After: ", $attribute->parentNode->tagName, "\n";
@@ -57,19 +57,19 @@
 Before: root
 After: root
 Before: root
-Not Found Error
+DOMException: Not Found Error
 After: root
 Before: root
-Not Found Error
+DOMException: Not Found Error
 After: root
 Before: child
 After: child
 Before: child
-Not Found Error
+DOMException: Not Found Error
 After: child
 Before: child
-Not Found Error
+DOMException: Not Found Error
 After: child
 Before: child
-Not Found Error
+DOMException: Not Found Error
 After: child