there's nothing wrong with goto itself. But there are many things wrong with it's misuses.
You need to be very careful when you decide to use it.
IMO the code above ( unless possible declaration problems in unshown code ) is quite fine
I don't like it. I would rather see RAII handling the resources for you. The above strikes me as one of those things that can be casually shrugged off but is still more error prone and harder to maintain.
Well, your code is a good example why goto is a no go.
The label 'ERROR' is misleading since that code below will be executed regardless whether an error occured or not. You must keep that in mind.
The code above that label may want to participate in the result of a function below the label (executed independently of the error). This should be no problem, but how will you accomplish that?
i think goto will not serve the purpose in catch{} block. As after executing the code below ERROR label the control never returns back and that function stack gets unwind.
i think goto will not serve the purpose in catch{} block. As after executing the code below ERROR label the control never returns back and that function stack gets unwind.
That statement doesn't make any sense. Why goto out of the catch? The purpose of the catch is to handle the exception, do cleanup and then rethrow or continue on. The stack doesn't "unwind" in your example. The function would just return which is not the same thing as propagating an exception.
You could easily do a google search on goto and read about the many reasons that people like it or don't like it. The discussion has been had many times but it is obvious that you didn't bother to do any research.
The snippet appears to be an attempt to use two different error handling policies in the same function. It makes me think that the program is not exception safe but happens to use a library or something that commonly throws. The gotos are just silly.
There are important differences between C and C++ exception handling, particularly with how resources are cleaned up. Make sure to implement some proper RAII.
Also keep in mind that C is not designed to work around an exception model, so design your algorithms appropriately.