Move NTL error handler out of libsingular, otherwise it takes over Sage's error handler and makes it quit on NTL errors.
See https://www.singular.uni-kl.de/forum/viewtopic.php?f=10&t=2769 and https://trac.sagemath.org/ticket/24735#comment:29
Rebased from upstream commit https://github.com/Singular/Sources/commit/502cf86d0bb2a96715be6764774b64a69c1ca34c

From 502cf86d0bb2a96715be6764774b64a69c1ca34c Mon Sep 17 00:00:00 2001
From: Hans Schoenemann <hannes@mathematik.uni-kl.de>
Date: Wed, 25 Jul 2018 11:03:32 +0200
Subject: [PATCH] move error handler for factory,NTL to the non-libSingular part

(see forum: "NTL error handling", for SAGE)

diff --git a/Singular/cntrlc.cc b/Singular/cntrlc.cc
index 622495490c..874a5deb79 100644
--- a/Singular/cntrlc.cc
+++ b/Singular/cntrlc.cc
@@ -20,6 +20,14 @@
 #include "Singular/links/silink.h"
 #include "Singular/links/ssiLink.h"
 
+#ifdef HAVE_NTL
+#include <NTL/version.h>
+#include <NTL/tools.h>
+#ifdef NTL_CLIENT
+NTL_CLIENT
+#endif
+#endif
+
 /* undef, if you don't want GDB to come up on error */
 
 #define CALL_GDB
@@ -549,11 +557,20 @@ static void stack_trace (char *const*args)
 
 #  endif /* !__OPTIMIZE__ */
 
-/*2
-* init signal handlers
-*/
+/// init signal handlers and error handling for libraries: NTL, factory
 void init_signals()
 {
+// NTL error handling (>= 9.3.0) ----------------------------------------
+#ifdef HAVE_NTL
+#if (((NTL_MAJOR_VERSION==9)&&(NTL_MINOR_VERSION>=3))||(NTL_MAJOR_VERSION>=10))
+  ErrorMsgCallback=WerrorS;
+  ErrorCallback=HALT;
+#endif
+#endif
+// factory error handling: -----------------------------------------------
+  factoryError=WerrorS;
+
+// signal handler -------------------------------------------------------
   #ifdef SIGSEGV
   si_set_signal(SIGSEGV,(si_hdl_typ)sigsegv_handler);
   #endif
diff --git a/Singular/misc_ip.cc b/Singular/misc_ip.cc
index 49eddaae6f..3d5775edd7 100644
--- a/Singular/misc_ip.cc
+++ b/Singular/misc_ip.cc
@@ -1316,16 +1316,6 @@ static BOOLEAN iiCrossProd(leftv res, leftv args)
   On(SW_USE_EZGCD_P);
   On(SW_USE_QGCD);
   Off(SW_USE_NTL_SORT); // may be changed by an command line option
-  factoryError=WerrorS;
-
-// NTL error handling (>= 9.3.0)
-#ifdef HAVE_NTL
-#if (((NTL_MAJOR_VERSION==9)&&(NTL_MINOR_VERSION>=3))||(NTL_MAJOR_VERSION>=10))
-  ErrorMsgCallback=WerrorS;
-  ErrorCallback=HALT;
-#endif
-#endif
-
 // memory initialization: -----------------------------------------------
     om_Opts.OutOfMemoryFunc = omSingOutOfMemoryFunc;
 #ifndef OM_NDEBUG
