Design idea: Very early ideas about handle errors/exceptions in carbon using try/catch #2049
Replies: 5 comments 6 replies
-
Allowing only 1 exception would mean that you can't do this:
You would need to rethrow specific exceptions you are not handling in every try catch block. Also, exceptions would not be identifiable at compile-time. For example, if an exception is changed or removed, the compiler wouldn't be able to tell you about it:
Software that controls a nuclear reactor for example should not simply shut down because a developer forgot to check for a division by zero. We can't guarantee human error will not occur when developing software, but we can and must do a better job than shutting down when it does happen.
That would mean that attackers simply need to find a single exploit that divides by zero for example, and they can easily shut down the web service remotely. |
Beta Was this translation helpful? Give feedback.
-
try catch will need finally block as in java/javascript. This will come in handy when we are reading files and some exception is occurring during that time. we can give the syntax for closing file in finally. Also the exceptions which are not handled by catch should be rethrown. We can mention the throws in function like in java so that eventually the default handler would catch the exception or we can simply mention "rethrow e" at the end of the catch or finally block so that the function which is calling this function can handle the exception. |
Beta Was this translation helpful? Give feedback.
-
I'm converting this to a discussion because it doesn't seem to be an issue that can be resolved with a commit in the near term. |
Beta Was this translation helpful? Give feedback.
-
How do libraries know which range they can use? If you use several different libraries in your project, that each use several different dependencies themselves you might not even be aware of, how do you make sure error indices are unique? If they are not, then how would you be able to tell where an error comes from? Parse the call stack? That's a lot of additional code. |
Beta Was this translation helpful? Give feedback.
-
In case you haven't seen them, you might want to take a look at the all errors are values principle, and p0301, the underlying proposal for that principle. One thing that's not clear to me is how you envision handling errors within expressions. For example, suppose I have code like
This looks like it models
Why can't users define their own error types? Notice in particular that this restriction makes it vastly harder to design the |
Beta Was this translation helpful? Give feedback.
-
This a are very early ideas about error handling in carbon
In my opinion and experiences how programmer of C/C++/Java/TypeScript/JavaScript the Exceptions are not need to be a class. Is more of sufficient a simple struct
Key points:
What about C++ Exceptions?
Here my idea.
Support the CPP.Exception only with additional catch
About the defering a null pointer, division by zero,
I think carbon need a generate a error by default and not only kill the app.
I used for c++ project the setjmp/longjmp to catch this kind execeptions.
Why not let to program die by default?. Because to some kind a http backend this default behavior can be exploited to make DOS attack. Shutdown the service.
Beta Was this translation helpful? Give feedback.
All reactions