diff --git a/tests/test_write.cpp b/tests/test_write.cpp
index ad6c409..230d652 100644
--- a/tests/test_write.cpp
+++ b/tests/test_write.cpp
@@ -574,3 +574,41 @@ TEST_XML_FLAGS(write_mixed, "premid\npostfin\n\n\n"), STR("\t"), 0);
CHECK_NODE_EX(doc, STR("\n\t\n\tpremid\n\t\tpostfin\n\t\n\n"), STR("\t"), format_indent);
}
+
+#ifndef PUGIXML_NO_EXCEPTIONS
+struct throwing_writer: pugi::xml_writer
+{
+ virtual void write(const void*, size_t)
+ {
+ throw std::runtime_error("write failed");
+ }
+};
+
+TEST_XML(write_throw_simple, "")
+{
+ try
+ {
+ throwing_writer w;
+ doc.print(w);
+
+ CHECK_FORCE_FAIL("Expected exception");
+ }
+ catch (std::runtime_error&)
+ {
+ }
+}
+
+TEST_XML(write_throw_encoding, "")
+{
+ try
+ {
+ throwing_writer w;
+ doc.print(w, STR("\t"), format_default, encoding_utf32_be);
+
+ CHECK_FORCE_FAIL("Expected exception");
+ }
+ catch (std::runtime_error&)
+ {
+ }
+}
+#endif