Click here to Skip to main content
Click here to Skip to main content
Alternative Tip

The goto-less goto!

By , 7 Feb 2011
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 will eventually end up being messy.


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

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... PinmemberWolfgang_Baron10-Feb-11 4:37 
GeneralPerformance would greatly suffer? For using the RAII idiom? ... PinmemberJörgen Sigvardsson9-Feb-11 7:17 
GeneralReason for my vote of 2 While your code would look nice, per... PinmemberWolfgang_Baron9-Feb-11 4: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 | Mobile
Web01 | 2.8.140415.2 | Last Updated 7 Feb 2011
Article Copyright 2011 by Jörgen Sigvardsson
Everything else Copyright © CodeProject, 1999-2014
Terms of Use
Layout: fixed | fluid