Re: unexpected exception handler



George <George@xxxxxxxxxxxxxxxxxxxxxxxxx> wrote:
I hear some points to support exception specification is because,
only if developer could clearly list all the possible exceptions a
function may thrown, it is well designed function -- all exception
situations are thought.

List them in a comment next to the function declaration, or in the
documentation.

Realize that the compiler has to actually generate code to enforce
exception specification at runtime. If you know your function never
throws exceptions other than those on the list, by writing an exception
specification you force the compiler to generate dead code that you know
will never run. And if you know your function _will_ throw exceptions
outside the list, then what's the point of putting in an exception
specification that's essentially a lie?

If we do not have exception specification, and simply catch(...),
there may be some exceptions we (developer) never thought of in
design/implementation.

If there are exceptions you didn't think of, then you can't clearly list
all the possible exceptions a function may throw. By your own
definition, such a function is not well designed. So go back and design
it better.

I don't see how catch(...) is helpful. What are you going to do in such
a handler, other than perhaps some cleanup and then rethrow?
--
With best wishes,
Igor Tandetnik

With sufficient thrust, pigs fly just fine. However, this is not
necessarily a good idea. It is hard to be sure where they are going to
land, and it could be dangerous sitting under them as they fly
overhead. -- RFC 1925


.



Relevant Pages

  • Re: unexpected exception handler
    ... only if developer could clearly list all the possible exceptions a ... exceptions other than those on the list, ... design/implementation. ... providing an exception specification doesn't do much of anything ...
    (microsoft.public.vc.language)
  • Re: unexpected exception handler
    ... I am not sure whether there are any potential exceptions at ... only if developer could clearly list all the possible exceptions a ... specification you force the compiler to generate dead code that you know ... design/implementation. ...
    (microsoft.public.vc.language)
  • Re: Exception handling and logging.
    ... > I am creating a .NET library with functionality that I am giving to ... This other developer does not want to be bother ... with exceptions because he really has no choice. ... > He want however me to log all exception to a common logging system. ...
    (microsoft.public.dotnet.framework)
  • Re: Casting a string to a double
    ... When writing a class that implements a .Parse method the developer can ... choose to throw different exceptions for different problems and the user of ...
    (microsoft.public.dotnet.languages.csharp)
  • RE: SEH and C++ ExceptionHandling
    ... Exceptions, including the old setjmp and longjmp seem to have been ... stack unwinding that can be seen as an alternative return mechanism. ... Software Developer ... > For example, why, when I throw an exception does the kernel get involved? ...
    (microsoft.public.windowsce.embedded.vc)

Loading