--- pari-2.5.0/src/headers/paricom.h-pre	2011-05-30 02:28:34.000000000 -0700
+++ pari-2.5.0/src/headers/paricom.h	2018-09-16 00:04:16.527215600 -0700
@@ -73,6 +73,10 @@ extern void (*cb_pari_sigint)(void);
 extern int (*cb_pari_handle_exception)(long);
 extern void (*cb_pari_err_recover)(long);
 
+#define CB_EXCEPTION_FLAGS 1
+extern int cb_exception_resets_avma;
+extern int cb_exception_flushes_err;
+
 enum manage_var_t {
   manage_var_create,
   manage_var_delete,
--- pari-2.5.5/src/language/eval.c.orig	2013-06-24 16:06:58.000000000 -0700
+++ pari-2.5.5/src/language/eval.c	2019-02-27 04:19:10.374415800 -0800
@@ -1323,7 +1323,8 @@ evalstate_reset(void)
   reset_break();
   compilestate_reset();
   parsestate_reset();
-  avma = top;
+  if (!cb_exception_resets_avma)
+    avma = top;
 }
 
 void
--- pari-2.7.0/src/language/init.c.orig	2014-03-20 01:59:28.000000000 -0700
+++ pari-2.7.0/src/language/init.c	2019-03-01 03:44:51.207967500 -0800
@@ -93,6 +93,9 @@ void (*cb_pari_pre_recover)(long);
 void (*cb_pari_err_recover)(long);
 const char * pari_library_path = NULL;
 
+int cb_exception_resets_avma = 0;
+int cb_exception_flushes_err = 0;
+
 static THREAD GEN global_err_data;
 THREAD jmp_buf *iferr_env;
 const long CATCH_ALL = -1;
@@ -885,8 +888,11 @@ err_recover(long numerr)
   evalstate_reset();
   killallfiles();
   pari_init_errcatch();
-  out_puts(pariErr, "\n");
-  pariErr->flush();
+
+  if (!cb_exception_flushes_err) {
+    out_puts(pariErr, "\n");		/* What is this doing in generic code?  It was flushed already, so this is just an empty error message! */
+    pariErr->flush();			/* If an empty line is needed by gp, this should be done in gp's error handler! */
+  }
 
   cb_pari_err_recover(numerr);
 }
@@ -966,7 +972,8 @@ pari_sigint(const char *time_s)
   out_puts(pariErr, "user interrupt after ");
   out_puts(pariErr, time_s);
   out_term_color(pariErr, c_NONE);
-  pariErr->flush();
+  if (!cb_exception_flushes_err)
+    pariErr->flush();
   if (cb_pari_handle_exception)
     recover = cb_pari_handle_exception(-1);
   if (!recover && !block)
@@ -1318,7 +1325,8 @@ pari_err(int numerr, ...)
   pari_err_display(E);
   out_term_color(pariErr, c_NONE);
   va_end(ap);
-  pariErr->flush();
+  if (!cb_exception_flushes_err)
+    pariErr->flush();
   if (cb_pari_handle_exception &&
       cb_pari_handle_exception(numerr)) return;
   err_recover(numerr);