cesium-native icon indicating copy to clipboard operation
cesium-native copied to clipboard

Disable exceptions by default

Open kring opened this issue 3 years ago • 3 comments

Some of our downstream projects (including Cesium for Unreal) ship with exceptions disabled. But cesium-native itself has them enabled. This is kind of ok as long as a) cesium-native itself is built with exceptions enabled, and b) the exceptions never leave cesium-native code. But it's easy to get this wrong. For example, a try/catch within a method is fine, unless that method happens to be inline or a template. In which case an exceptions-disabled project that tries to use it will fail to compile.

A safer approach, given that we expect cesium-native to be used in environments where exceptions aren't available, would be disable exceptions in cesium-native entirely. That way any attempts to use them would be immediately flagged.

There are some places where this would be pretty awkward, though, which is why we haven't done it already. We'll also likely need to change how errors are reported through AsyncSystem, and may even need to replace Async++.

kring avatar Apr 16 '21 10:04 kring

This is at least related to (or maybe a generalization of) https://github.com/CesiumGS/cesium-native/issues/205 . Also related: https://github.com/CesiumGS/cesium-native/issues/76 (disabling exceptions was mentioned there, at least).

If completely disabling exceptions (on a level of compiler flags) would make it impossible to even use certain third-parts libs, one would at least have to carefully and diligently examine each call to a third-party lib and wrap that call into some { try { } catch () } noexcept version. The question of "What should happen instead of throwing?" must be examined on a case-by-case basis, and probably include simple solutions like "Just 'log' the error and do nothing" or "Return some optional" to cases where it might be tricky to come up with a solution that fits all application cases, like the "I expect a vector to be normalized"-assumption in the linked issue.

javagl avatar Apr 16 '21 13:04 javagl

It's not urgent by any means, but I'm curious if there are updates on this. For an internal project at Cesium that uses Cesium for Unreal, exceptions have been enabled in order to get the project to build (currently we are creating a Development build in our travis CI). However, as exceptions are always off in Shipping builds (re: https://github.com/CesiumGS/cesium-unreal/issues/387#issuecomment-832670363), it would be great to eventually resolve this in the cesium-native repo.

xuelongmu avatar Jun 23 '21 16:06 xuelongmu

This one is currently not in the work at the moment. Unreal plugin travis CI is built with shipping build enabled I think. For the crashing in the shipping build that is related to Sqlite (https://github.com/CesiumGS/cesium-unreal/issues/245), I believe the fix is already in the main branch currently

baothientran avatar Jun 23 '21 17:06 baothientran