Click here to Skip to main content
13,096,858 members (82,886 online)
Click here to Skip to main content
Add your own
alternative version

Tagged as


2 bookmarked
Posted 29 Apr 2010

The goto-less goto!

, 29 Apr 2010
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
Engineer Cutlite Penta S.r.l.
Italy Italy
No Biography provided

You may also be interested in...

Comments and Discussions

GeneralReason for my vote of 1 Not to repeat the other reasons for ... Pin
Wolfgang_Baron9-Feb-11 5:35
memberWolfgang_Baron9-Feb-11 5:35 
GeneralI am in complete agreement with those who say exceptions sho... Pin
jim lahey26-Jan-11 3:45
memberjim lahey26-Jan-11 3:45 
General"It is not wise to throw exception" - Really? It's strange b... Pin
Sauro Viti24-Jan-11 22:31
memberSauro Viti24-Jan-11 22:31 
GeneralReason for my vote of 2 As Klaus said, it is not wise to thr... Pin
Pravin Patil, Mumbai24-Jan-11 21:38
memberPravin Patil, Mumbai24-Jan-11 21:38 
GeneralReason for my vote of 1 First throwing exceptions is very ex... Pin
Klaus Luedenscheidt24-Jan-11 18:48
memberKlaus Luedenscheidt24-Jan-11 18:48 
GeneralRe: Have you tried it? One can throw a lot of exceptions in a si... Pin
Eddy Vluggen12-Oct-11 7:12
memberEddy Vluggen12-Oct-11 7:12 

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

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

Permalink | Advertise | Privacy | Terms of Use | Mobile
Web01 | 2.8.170813.1 | Last Updated 29 Apr 2010
Article Copyright 2010 by Sauro Viti
Everything else Copyright © CodeProject, 1999-2017
Layout: fixed | fluid