Re: Exceptions creating Exceptional Problems!

Abhijit Menon-Sen <[email protected]> Sun, 9 Jan 2005 20:59:29 +0530
Newsgroups gmane.user-groups.linux.delhi.devel
Message-ID <[email protected]>
At 2005-01-09 09:18:53 -0500, [email protected] wrote:
>
> >     if ( ... ) {
> >         Socket s;
> >     }
> > 
> >     s.foo();
> 
> Fine, but any work-arounds? I hope you understood my problem.

"Work-arounds"? You seem to think this is some kind of bug. It is not.
If you want a variable to be visible in both an inner and outer scope,
it must be declared in the outer scope.

    Socket s;
    try {
        s.foo();
    }
    catch (Error e) {
        s.bar();
    }

Of course, if it is the constructor that's throwing an exception, what
do you hope to do with the "object" when you catch that exception? It
won't be an object, and you can't expect to be able to use it at all.

-- ams