Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

C++ exceptions vs. C# exceptions

In an old blog entry titled Cleaner, more elegant, and harder to recognize, the author states:

In C++ it's not quite so bad because C++ exceptions are raised only at specific points during execution. In C#, exceptions can be raised at any time.

What exactly does he mean by that?

like image 539
fredoverflow Avatar asked Jun 14 '12 08:06

fredoverflow


1 Answers

First, I would hesitate to accuse Raymond Chen of confusing anything with anything.

I suspect he means that in C++, exceptions are only thrown where there exists a throw statement. As long as you go deep enough into your code and library functions, you can determine exactly where exceptions may be thrown from. On the other hand, in C# there may be exceptions thrown by the runtime environment at any time. For example, you could get a security exception trying to call any function in any other assembly.

like image 171
Greg Hewgill Avatar answered Sep 26 '22 18:09

Greg Hewgill