|
| | #1 (permalink) |
| Banned Join Date: Nov 2003
Posts: 1,219
| [C++] Try/Throw/Catch So in my software design class this semester we just wrote a program (CS 216 Program 3) to access data from files, displaying the results to the user. Really easy program, had no problem with it. Now, fast forward to our current assignment (CS 216 Program 4) where we have to implement the same program, with the major difference being it has to be in perl. I wrote the perl program with ease, but another portion of the assignment was to add file error checking to our 3rd program using try/throw/catch. This is where I'm at a loss. My functions to retrieve the file contents are in classes and I'm not sure how to set up to throw the errors to the main program. I'm including my source code so any interested persons can sift through it and hopefully help me out. Oh, and its due tonight at midnight. I figured that this would be the easy part so I put off doing it as long as I possibly could (figured I'd finish it in an hour or so). Little did I know it was going to be the part that killed me. ![]() Anyway, I'm in desperate need of some guidance and if anyone wants to help a brother out just AIM me (breakmyname). |
| | |
| | #3 (permalink) |
| Registered User Join Date: Feb 2006
Posts: 1,634
+7 Internets | Exceptions propagate up the call stack from where they occurred. So if in main.cpp you call Code:
It looks like that's what your professor wants; the exceptions being thrown when you find an error in the input data in the empClass and storeClass implementations, and then the exceptions being caught in your main() function and handled with appropriate error output. EDIT: you got owned brosef -----v Last edited by Fog : 11-08-2007 at 01:54 PM. |
| | |
| | #4 (permalink) |
| Crankier than the Kong Join Date: Nov 2005 Location: DigiPen
Posts: 894
| So here's the basics of it: In the main program you're going to do the following: Code:
So as a basic example (assume all relevant #includes, using directives, etc.): Code:
|
| | |
| | #5 (permalink) |
| Banned Join Date: Nov 2003
Posts: 1,219
| Alright, awesome guys. Thanks a bunch. For this, I'm throwing a string called errorMsg and just returning 1 to the main program. Now the obstacle is the pattern matching, was super easy in perl but will apparently be a hassle for C++. I suppose thats the point of the assignment, haha. If I have an input (string) with 2 characters that can have all alphanumeric characters, what would be an intuitive way to handle that? With my first name/last name throw block my conditions are: Code:
Update: Got the thing working! Just need to refine my pattern matching and I'm home free. Thanks so much guys. FoH coders for the win. Last edited by tikkus : 11-08-2007 at 02:33 PM. |
| | |
![]() |
| Thread Tools | Search this Thread |
| Display Modes | Rate This Thread |
| |