diff --git a/examples/rustc-driver-getting-diagnostics.rs b/examples/rustc-driver-getting-diagnostics.rs
index f9fe7f5f3..7b6240323 100644
--- a/examples/rustc-driver-getting-diagnostics.rs
+++ b/examples/rustc-driver-getting-diagnostics.rs
@@ -77,10 +77,10 @@ fn main() {
         locale_resources: rustc_driver::DEFAULT_LOCALE_RESOURCES,
         lint_caps: rustc_hash::FxHashMap::default(),
         psess_created: Some(Box::new(|parse_sess| {
-            parse_sess.dcx = DiagCtxt::new(Box::new(DebugEmitter {
+            parse_sess.set_dcx(DiagCtxt::new(Box::new(DebugEmitter {
                 source_map: parse_sess.clone_source_map(),
                 diagnostics,
-            }))
+            })));
         })),
         register_lints: None,
         override_queries: None,
@@ -98,6 +98,9 @@ fn main() {
                 let _ = tcx.analysis(());
             });
         });
+        // If the compiler has encountered errors when this closure returns, it will abort (!) the program.
+        // We avoid this by resetting the error count before returning
+        compiler.sess.dcx().reset_err_count();
     });
     // Read buffered diagnostics.
     buffer.lock().unwrap().iter().for_each(|diagnostic| {
diff --git a/src/rustc-driver-getting-diagnostics.md b/src/rustc-driver-getting-diagnostics.md
index db8be88db..a92522684 100644
--- a/src/rustc-driver-getting-diagnostics.md
+++ b/src/rustc-driver-getting-diagnostics.md
@@ -8,7 +8,7 @@ otherwise be printed to stderr.
 To get diagnostics from the compiler,
 configure [`rustc_interface::Config`] to output diagnostic to a buffer,
 and run [`TyCtxt.analysis`]. The following was tested
-with <!-- date-check: may 2024 --> `nightly-2024-05-09`:
+with <!-- date-check: september 2024 --> `nightly-2024-09-16`:
 
 ```rust
 {{#include ../examples/rustc-driver-getting-diagnostics.rs}}