| | |
How To Return to Main()
Please support our C++ advertiser: Intel Parallel Studio Home
![]() |
It's freeware in the public domain. Try this, it works:
c++ Syntax (Toggle Plain Text)
struct Cry { const char* what() const { return "Mummy, I\'m afraid!"; } }; void Lots() { 2*2==4; throw Cry(); } void of () { Lots(); } void functions () { of(); } int main() { try { functions(); } catch(Cry mail) { cout << mail.what() << "..\n"; cout << "I\'m very glad to see you!" << endl; } catch(...) { cout << "Bye forever ;(" << endl; } return 0; }
ya i am a newbie!
i want to return to the lines above ,where i call the function,i cant design my program.
i want to return to a menu which is in the main and if the user wants to run the function again then he can select it again from the main
thanks for posting,but can u plz explain a bit?
i want to return to the lines above ,where i call the function,i cant design my program.
i want to return to a menu which is in the main and if the user wants to run the function again then he can select it again from the main
•
•
•
•
It's freeware in the public domain. Try this, it works:
c++ Syntax (Toggle Plain Text)
struct Cry { const char* what() const { return "Mummy, I\'m afraid!"; } }; void Lots() { 2*2==4; throw Cry(); } void of () { Lots(); } void functions () { of(); } int main() { try { functions(); } catch(Cry mail) { cout << mail.what() << "..\n"; cout << "I\'m very glad to see you!" << endl; } catch(...) { cout << "Bye forever ;(" << endl; } return 0; }
Better look at http://www.cprogramming.com/tutorial/exceptions.html or search Google for C++ exception handling.
It's possible to use exceptions for the program control (however as usually it's considered as a bad style).
I think no special problems to design your menu handling to provide fast return to the main loop without gotos and exceptions...
It's possible to use exceptions for the program control (however as usually it's considered as a bad style).
I think no special problems to design your menu handling to provide fast return to the main loop without gotos and exceptions...
•
•
Join Date: Aug 2008
Posts: 149
Reputation:
Solved Threads: 8
goto's can only jump to labels within the same function,
so I don't think you will be able to do it with goto's if you are in some far away function.
There are any beautifull way of doing what you want without having to redesign you program or use c++ exceptions.
On a general note goto should be avoided.
I've only found them usefill in some crazy switch statements.
Which basicly changes it to a jump table.
so I don't think you will be able to do it with goto's if you are in some far away function.
There are any beautifull way of doing what you want without having to redesign you program or use c++ exceptions.
On a general note goto should be avoided.
I've only found them usefill in some crazy switch statements.
Which basicly changes it to a jump table.
Maybe you should just try to call 'return <something>' in your code ...
After the return instruction no code is executed anymore so the function will go back to 'main()' (if the function is called from the 'main()' function)
P.S. : Can you please post us some code so we can take a look at what exactly you do mean?
After the return instruction no code is executed anymore so the function will go back to 'main()' (if the function is called from the 'main()' function)
P.S. : Can you please post us some code so we can take a look at what exactly you do mean?
Last edited by tux4life; Mar 11th, 2009 at 2:57 pm.
![]() |
Similar Threads
- Problem About Trying to Return to Main. (C)
- return to main() and ending a program. (C)
- Why NOT void main() (C++)
- Function Back to Main (C++)
- Return variable (C++)
- Calling other programs which take and return variables (C)
Other Threads in the C++ Forum
- Previous Thread: Passing 2D Array of Pointers into a function
- Next Thread: Problem with AVL tree!
| Thread Tools | Search this Thread |
api array arrays based beginner binary bitmap c++ c/c++ calculator char class classes code compile compiler console conversion count data delete deploy desktop developer directshow dll download dynamic encryption error file forms fstream function functions game getline givemetehcodez google graph gui homeworkhelp homeworkhelper iamthwee ifstream input int integer java lib linkedlist linker linux list loop looping loops map math matrix memory news node number output parameter pointer problem program programming project proxy python read recursion recursive return string strings struct temperature template templates test text text-file tree unix url variable vector video visual visualstudio win32 windows winsock word wordfrequency wxwidgets






