| | |
Exception Handling
Please support our C++ advertiser: Intel Parallel Studio Home
![]() |
Hi, I took a course in JAVA and learned about exceptions...I'm not sure how to throw and catch in C++. Can I get some help please???
Beware of the Rancor. I'm not kidding.
If it doesn't compile, try saying "By the power of MegaMan!!!" <this has kinda worked for me, actually...>
Scotland is NOT North Britain, Glasgow does NOT rhyme with "cow", and Robbie Burns is...well, if you don't already know who he was, you're kinda screwed.
If it doesn't compile, try saying "By the power of MegaMan!!!" <this has kinda worked for me, actually...>
Scotland is NOT North Britain, Glasgow does NOT rhyme with "cow", and Robbie Burns is...well, if you don't already know who he was, you're kinda screwed.
Since I know little about it, I'll point you here.
"One of the methods used by statists to destroy capitalism consists in establishing controls that tie a given industry hand and foot, making it unable to solve its problems, then declaring that freedom has failed and stronger controls are necessary." --Ayn Rand
One of expecption handlings greatest claims to fame is ability to unroll the stack. Lets suppose you have subroutines "A", "B", "C". Your main code establishes a try block, where in it you call "A" and then "A" calls "B" and "B" calls "C". In "C" there is an error and you throw and expection and it will revert right back to the catch statement in your main module re-establishing the stack as if it had returned normally to that point
Somewhat similiar to the way ON ERROR GOSUB works in VB
So what I try to do is in all my subs and fuctions just throw exceptions and implement appropriate try blocks in the main body of program.
http://relisoft.com has some pretty good tutorials on this already incorportated into full functioning programs.
Somewhat similiar to the way ON ERROR GOSUB works in VB
So what I try to do is in all my subs and fuctions just throw exceptions and implement appropriate try blocks in the main body of program.
http://relisoft.com has some pretty good tutorials on this already incorportated into full functioning programs.
Last edited by Tight_Coder_Ex; Sep 2nd, 2007 at 10:58 am. Reason: Fixed relisoft link
•
•
Join Date: Dec 2006
Posts: 1,089
Reputation:
Solved Threads: 164
>> I took a course in JAVA and learned about exceptions...I'm not sure how to throw and catch in C++.
the fundamental difference is the use of the 'resource acquisition is initialization' technique in resource management. the c++ philosophy is
a. error handling code must be clearly seperate from normal code
b. you should not have to write error handling code (read no finally scattered all around the place to clean up when exceptions are thrown) except at the place where you attempt to handle the error.
c. the possibility of an error is not deemed to be an error. (exceptions are not checked at compile-time; if exception specifications are not violated at runtime there is no error).
d. the exception mechanism (as the name suggests) is designed to handle exceptional situations; (for example, when you iterate over a sequence, there is nothing exceptional about reaching its end (i would say that never being able to reach the end would be exceptional).
e. exceptions are expensive at runtime (stack unwind is required), but should cause minimum overhead if no exceptional situation occurs. exceptions are the exception rather than the rule.
so your java experience might in some ways be a disadvantage; you should be willing to unlearn a few things.
here are a few links which deal with the conceptual (rather than syntactic) differences between java and c++ exceptions.
http://www.hackcraft.net/raii/
http://en.wikipedia.org/wiki/Resourc...Initialization
http://www.informit.com/articles/art...&seqNum=8&rl=1
http://www.artima.com/intv/modern3.html
http://www.research.att.com/~bs/3rd_safe.pdf
the last link (appendix E) is about exception safety in the c++ standard library; if you are starting out on c++, read section E.6 'implications for library users'.
the fundamental difference is the use of the 'resource acquisition is initialization' technique in resource management. the c++ philosophy is
a. error handling code must be clearly seperate from normal code
b. you should not have to write error handling code (read no finally scattered all around the place to clean up when exceptions are thrown) except at the place where you attempt to handle the error.
c. the possibility of an error is not deemed to be an error. (exceptions are not checked at compile-time; if exception specifications are not violated at runtime there is no error).
d. the exception mechanism (as the name suggests) is designed to handle exceptional situations; (for example, when you iterate over a sequence, there is nothing exceptional about reaching its end (i would say that never being able to reach the end would be exceptional).
e. exceptions are expensive at runtime (stack unwind is required), but should cause minimum overhead if no exceptional situation occurs. exceptions are the exception rather than the rule.
so your java experience might in some ways be a disadvantage; you should be willing to unlearn a few things.
here are a few links which deal with the conceptual (rather than syntactic) differences between java and c++ exceptions.
http://www.hackcraft.net/raii/
http://en.wikipedia.org/wiki/Resourc...Initialization
http://www.informit.com/articles/art...&seqNum=8&rl=1
http://www.artima.com/intv/modern3.html
http://www.research.att.com/~bs/3rd_safe.pdf
the last link (appendix E) is about exception safety in the c++ standard library; if you are starting out on c++, read section E.6 'implications for library users'.
Last edited by vijayan121; Sep 2nd, 2007 at 2:52 pm.
![]() |
Similar Threads
- Exception handling statement. (JavaScript / DHTML / AJAX)
- Error/Exception handling help (Python)
- Borland C++ EDBEngineError exception (C++)
- Exception Handling (C++)
- purpose of exception handling 'finally' clause (Java)
- Arithmetic Exceptions and exception-handling statements (Java)
Other Threads in the C++ Forum
- Previous Thread: Reading a Registry Key path from a file
- Next Thread: meta-library for compile time matrix operations
| Thread Tools | Search this Thread |
api array based binary c++ c/c++ calculator char char* class classes code coding compile console conversion count database delete deploy desktop developer directshow dll download dynamic dynamiccharacterarray email encryption error file forms fstream function functions game givemetehcodez google graph gui homeworkhelp iamthwee ifstream input int integer java lib linkedlist linker linux list loop looping loops map math matrix memory multiple news number numbertoword output parameter pointer problem program programming project python random read recursion recursive reference return rpg sorting string strings struct temperature template templates test text text-file tree unix url variable vector video visualstudio win32 windows winsock wordfrequency wxwidgets






