Click here to Skip to main content
11,439,025 members (78,330 online)
Click here to Skip to main content
Alternative Tip/Trick

Tagged as

The goto-less goto!

, 7 Feb 2011 CPOL
Rate this:
Please Sign up or sign in to vote.
Usually, gotos are used to clean up resources when exiting a function. I would recommend using the RAII[^] idiom. It also works works well in the presence of exceptions.For C# I would use IDisposable/using. If that's not possible, I'd use a finally clause to clean up.Everything else...
Usually, gotos are used to clean up resources when exiting a function. I would recommend using the
RAII[^] idiom. It also works works well in the presence of exceptions.

For C# I would use IDisposable/using. If that's not possible, I'd use a finally clause to clean up.

Everything else will eventually end up being messy.

License

This article, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)

Share

About the Author

Jörgen Sigvardsson
Software Developer (Senior)
Sweden Sweden
I make software.

Comments and Discussions

 
GeneralSorry, I assumed you were going to use exceptions for your r... Pin
Wolfgang_Baron10-Feb-11 5:37
memberWolfgang_Baron10-Feb-11 5:37 
GeneralPerformance would greatly suffer? For using the RAII idiom? ... Pin
Jörgen Sigvardsson9-Feb-11 8:17
memberJörgen Sigvardsson9-Feb-11 8:17 
GeneralReason for my vote of 2 While your code would look nice, per... Pin
Wolfgang_Baron9-Feb-11 5:44
memberWolfgang_Baron9-Feb-11 5:44 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.

| Advertise | Privacy | Terms of Use | Mobile
Web04 | 2.8.150506.1 | Last Updated 7 Feb 2011
Article Copyright 2011 by Jörgen Sigvardsson
Everything else Copyright © CodeProject, 1999-2015
Layout: fixed | fluid