summary refs log tree commit diff stats
diff options
context:
space:
mode:
-rw-r--r--compiler/ccgexprs.nim6
-rw-r--r--compiler/commands.nim4
-rw-r--r--compiler/options.nim1
-rw-r--r--doc/advopt.txt1
-rw-r--r--lib/system/excpt.nim2
-rw-r--r--web/news.txt7
6 files changed, 18 insertions, 3 deletions
diff --git a/compiler/ccgexprs.nim b/compiler/ccgexprs.nim
index fcc36e4fd..1a5334a98 100644
--- a/compiler/ccgexprs.nim
+++ b/compiler/ccgexprs.nim
@@ -2111,8 +2111,10 @@ proc expr(p: BProc, n: PNode, d: var TLoc) =
       initLocExpr(p, n.sons[0], a)
   of nkAsmStmt: genAsmStmt(p, n)
   of nkTryStmt:
-    if p.module.compileToCpp: genTryCpp(p, n, d)
-    else: genTry(p, n, d)
+    if p.module.compileToCpp and optNoCppExceptions notin gGlobalOptions:
+      genTryCpp(p, n, d)
+    else:
+      genTry(p, n, d)
   of nkRaiseStmt: genRaiseStmt(p, n)
   of nkTypeSection:
     # we have to emit the type information for object types here to support
diff --git a/compiler/commands.nim b/compiler/commands.nim
index 8dacebd83..2622d64f4 100644
--- a/compiler/commands.nim
+++ b/compiler/commands.nim
@@ -619,6 +619,10 @@ proc processSwitch(switch, arg: string, pass: TCmdLinePass, info: TLineInfo) =
     cAssembler = nameToCC(arg)
     if cAssembler notin cValidAssemblers:
       localError(info, errGenerated, "'$1' is not a valid assembler." % [arg])
+  of "nocppexceptions":
+    expectNoArg(switch, arg, pass, info)
+    incl(gGlobalOptions, optNoCppExceptions)
+    defineSymbol("noCppExceptions")
   else:
     if strutils.find(switch, '.') >= 0: options.setConfigVar(switch, arg)
     else: invalidCmdLineOption(pass, switch, info)
diff --git a/compiler/options.nim b/compiler/options.nim
index 82d18e242..29cdd96fb 100644
--- a/compiler/options.nim
+++ b/compiler/options.nim
@@ -66,6 +66,7 @@ type                          # please make sure we have under 32 options
                               # also: generate header file
     optIdeDebug               # idetools: debug mode
     optIdeTerse               # idetools: use terse descriptions
+    optNoCppExceptions        # use C exception handling even with CPP
   TGlobalOptions* = set[TGlobalOption]
   TCommands* = enum           # Nim's commands
                               # **keep binary compatible**
diff --git a/doc/advopt.txt b/doc/advopt.txt
index 02849498f..02aada4fb 100644
--- a/doc/advopt.txt
+++ b/doc/advopt.txt
@@ -69,6 +69,7 @@ Advanced options:
   --putenv:key=value        set an environment variable
   --NimblePath:PATH         add a path for Nimble support
   --noNimblePath            deactivate the Nimble path
+  --noCppExceptions         use default exception handling with C++ backend
   --excludePath:PATH        exclude a path from the list of search paths
   --dynlibOverride:SYMBOL   marks SYMBOL so that dynlib:SYMBOL
                             has no effect and can be statically linked instead;
diff --git a/lib/system/excpt.nim b/lib/system/excpt.nim
index df28c1493..8d1e04b8d 100644
--- a/lib/system/excpt.nim
+++ b/lib/system/excpt.nim
@@ -216,7 +216,7 @@ proc raiseExceptionAux(e: ref Exception) =
     if not localRaiseHook(e): return
   if globalRaiseHook != nil:
     if not globalRaiseHook(e): return
-  when defined(cpp):
+  when defined(cpp) and not defined(noCppExceptions):
     if e[] of OutOfMemError:
       showErrorMessage(e.name)
       quitOrDebug()
diff --git a/web/news.txt b/web/news.txt
index bf665c85c..d854347a5 100644
--- a/web/news.txt
+++ b/web/news.txt
@@ -17,6 +17,13 @@ Library Additions
 - The rlocks module has been added providing reentrant lock synchronization
   primitive
 
+Compiler Additions
+------------------
+
+- Added a new ``--noCppExceptions`` switch that allows to use default exception
+  handling (no ``throw`` or ``try``/``catch`` generated) when compiling to C++
+  code
+
 
 2016-01-27 Nim in Action is now available!
 ==========================================