Native Extension: cannot use 'throw' with exceptions disabled (SOLVED)

Hi,

I’m trying to update my native extension Look like things have changed :slight_smile:

Having a “cannot use ‘throw’ with exceptions disabled” error. I try to add “-fexceptions”, “-fcxx-exceptions” flags but they are invalid. seems like bundling for Windows is works but not for mac or linux. Am I missing something?

Building on MacOS.

My ext.manifest

name: DAABBCC

platforms:

 x86_64-win32:
  context:
   use-clang: true
 x86-win32:
  context:
   use-clang: true
 
 x86_64-osx:
  context:
   flags:      ["-stdlib=libc++","-fexceptions"]
   libs:       ["c++"]

 x86_64-linux:
  context:
   flags:      ["-std=c++11","-fexceptions"]

Also there is an other error/warning which I don’t know what it is.
What is the DLIB_LOG_DOMAIN ?

15

Ah! I find the DLIB_LOG_DOMAIN: https://www.defold.com/ref/dmLog/

Well, in general game engines don’t use exceptions, and we’re not either. We use “-fno-exceptions” and “-fno-rtti”. These are part of the command line when building the extensions.

What do you need exceptions for in this case?

Yes, the DLIB_LOG_DOMAIN warning is annoying, and it should be fixed in the next release (1.2.137)

2 Likes

I’m using this lib: https://github.com/lohedges/aabbcc/blob/master/src/AABB.cc
It has useful exceptions. It’s nice to have these exceptions when developing.
Is there any other way of doing this that you can suggest?

Thank you @Mathias_Westerdahl .

3 Likes

Well, if it’s an actual programmer error, I would call assert().

If it’s a user defined error, I would check those much higher up in the code. E.g. in this case in the Lua bindings, and then return luaL_error(L, "msg")

2 Likes

Thank you, I’ll keep in mind.
Also clang compiler is really fast for Windows build and my previous errors are gone. :tada:

1 Like

Hi @Mathias_Westerdahl
I come across this problem again and this time I hit the wall.
One of the lib that I’m using is Msgpack. Which is widely used binary serialization format especially for websocket data. Lib contains many exceptions. I can change them one by one of course but that is not a pleasant way.
Is there any other workaround which you can suggest?

I found this. It cause other problems but I can fix them(I guess)
If you have another suggestion I’m listening :slight_smile:

#if __cpp_exceptions
# define __try      try
# define __catch(X) catch(X)
# define __throw_exception_again throw
#else
# define __try      if (true)
# define __catch(X) if (false)
# define __throw_exception_again
#endif

I’m not an expert on msgpack, but shouldn’t it be possible to use the C version instead? Or does that also use exceptions somehow?

2 Likes

Thank you @sven.
Actually this is a generic question and not just about the msgpack.
Maybe using C version is an option but It cause me to change entire code :smirk:

1 Like

In general, games do not use exceptions due to the extra overhead in performance (and code bloat).
We too build without exceptions, and would encourage others to do so as well.

As @sven suggests, I would personally go for using the C version. It’s most likely not that much to change.I think fiddling with the defines as you try to is a slippery slope.

Next week, I’m going to start documenting Native Extensions a bit more, including this bit too.

5 Likes