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

Tagged as

The goto-less goto!

, 29 Apr 2010 CPOL
Rate this:
Please Sign up or sign in to vote.
Use C++ exceptions:try{ if (condition1_fails) throw 1; ... if (condition2_fails) throw 2; ... ... if (conditionN_fails) throw N; PerformActionOnAllSuccess(); DoNormalCleanup();}catch (int condition){ printf("The condition %d fails!\n",...
Use C++ exceptions:
   if (condition1_fails) throw 1;
   if (condition2_fails) throw 2;
   if (conditionN_fails) throw N;
catch (int condition)
   printf("The condition %d fails!\n", condition);
This way you have the overhead of the C++ exeption handling mechanism, but you'll have more control on what to do: you can for instance throw different exception types depending on the failed condition and catch them on different catch blocks.


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


About the Author

Sauro Viti
Italy Italy
No Biography provided

Comments and Discussions

GeneralReason for my vote of 1 Not to repeat the other reasons for ... PinmemberWolfgang_Baron9-Feb-11 6:35 
GeneralI am in complete agreement with those who say exceptions sho... Pinmemberjim lahey26-Jan-11 4:45 
General"It is not wise to throw exception" - Really? It's strange b... PinmemberSauro Viti24-Jan-11 23:31 
GeneralReason for my vote of 2 As Klaus said, it is not wise to thr... PinmemberPravin Patil, Mumbai24-Jan-11 22:38 
GeneralReason for my vote of 1 First throwing exceptions is very ex... PinmemberKlaus Luedenscheidt24-Jan-11 19:48 
GeneralRe: Have you tried it? One can throw a lot of exceptions in a si... PinmemberEddy Vluggen12-Oct-11 8:12 

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
Web01 | 2.8.150326.1 | Last Updated 29 Apr 2010
Article Copyright 2010 by Sauro Viti
Everything else Copyright © CodeProject, 1999-2015
Layout: fixed | fluid