-
Notifications
You must be signed in to change notification settings - Fork 1.9k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Catch exceptions in main()? #664
Comments
Codebase of this project doesn't use
|
How do you think about to adjust your main() functions to cope with exceptions like "std::bad_alloc" gracefully? Would you like to become independent from the technical detail that it is implementation-defined if stack unwinding will be performed by the compiler run time software after uncaught C++ exceptions are processed? |
exceptions in fish are only used for programming errors, or unrecoverable error conditions. That includes bad_alloc, out_of_range, and others. If exceptions are left unhandled, then throw will call abort, and we can get a backtrace (see for example #511). But If we add an outermost exception handling block, to my knowledge, we lose the backtrace information from where the exception is thrown. Also, the savings from building with -fno-exceptions are substantial. A quick test shows that enabling exception support increases fish's compiled size by 25% (from 601 KB to 754 KB). For these reasons I think we should not catch exceptions, and furthermore disable exception support whenever the standard library permits it. |
Where do you pass the parameter "no-exceptions"? Do you care if destructors will ever be called also in exceptional situations? |
Fish unconditionally terminates when an exception happens, and it also On 14 April 2013 18:15, Markus Elfring notifications@github.com wrote:
|
I find that Matthew presents a different view for "a production-quality main()". |
This looks like programming for unlikely. Of course if somebody will delete half of the files on the system, the fish isn't expected to start (unless you're lucky). If the system has 2MB of RAM, you shouldn't expect fish to start. If your system thinks that The problem is, where to set the boundary. Do you really think we should have check entire RAM before starting, checking whatever every binary does what it should, system calls don't randomly fail because person who wrote OS is evil, and find the processes can randomly can send SIGSEGV to fish? Bugfree software isn't possible. This is example of contrived bug. Of course if the fish doesn't have enough memory. But it does fail gracefully... by crashing with message "Out of memory" and backtrace. Just like in this example. Fish wasn't coded to detect lack of space left on device, yet it makes an error - and doesn't actually crash (because this isn't fatal error, fish still works, even if it cannot write to stdout).
I would make example of out-of-memory error, but I have lots of RAM, and I doubt I could cause that without causing lots of other issues in other programs that weren't prepared for that - I wouldn't want to restart my computer because random service crashed because out of memory. You cannot do much anyway, when you don't have memory - you can only fail.
|
We currently don't pass Destructors should never be called at exit in fish, because all they do is make exit slower. Necessary cleanups are handled in main(). We have a function |
How do you think about the possibility to let any users choose which error handling strategy should be applied for their tool implementation? |
Nope. fish will never have configuration option to change whatever to call destructors or not on exit. Or for how errors will be reported. fish doesn't want to copy zsh with its minor options that nobody cares about. Besides, that one would only contribute to configuration hell. Many things actually aren't configurable in fish, and I like that about fish. Besides, nobody cares whatever destructors are called or not on exit. Destructors in fish only free memory, they aren't used for flow control or saving data on hard drive. If you have modern operating system (that is, more modern than Windows 98), the memory is automatically freed when the process is closed. Markus Elfring notifications@github.com wrote: How do you think about the possibilty to let any users decide which error handling strategy should be applied for their tool implementation? — |
How do you think about to check if this special build parameter is supported by the used compiler? |
Yes, we only pass -fno-exceptions when compiling with g++ (or with clang in the Xcode build for OS X) |
Would you like to achieve a consistent parameter specification for different compilers? Do you care if open streams will be closed and functions which were registered with atexit() will be called? |
I don't think there is going to be any change to the current behaviour here. fish doesn't have any atexit functions, nor does it have streams open that need flushing. |
I expect that exception handling is usually supported by a C++ program. I wonder why your function "main" does not contain corresponding try and catch instructions so far.
How do you think about recommendations by Matthew Wilson in an article?
Would you like to adjust the implementation if you consider effects for uncaught/unhandled exceptions like they are described by Danny Kalev?
The text was updated successfully, but these errors were encountered: