User Name Password Register
DaniWeb IT Discussion Community
All
What is DaniWeb IT Discussion Community?
You're currently browsing the C++ section within the Software Development category of DaniWeb, a massive community of 455,987 software developers, web developers, Internet marketers, and tech gurus who are all enthusiastic about making contacts, networking, and learning from each other. In fact, there are 3,782 IT professionals currently interacting right now! Registration is free, only takes a minute and lets you enjoy all of the interactive features of the site.
Please support our C++ advertiser: Programming Forums
Views: 2341 | Replies: 4
Reply
Join Date: Mar 2007
Location: Petoskey, Mi
Posts: 38
Reputation: spankyg is an unknown quantity at this point 
Rep Power: 2
Solved Threads: 0
spankyg's Avatar
spankyg spankyg is offline Offline
Light Poster

Question New to try/catch

  #1  
Dec 5th, 2007
Can someone please explain to me just exactly this try/catch is doing? It doesn't seem to make any sense to me. Thank you in advance.
            
         case '\r':
			if (Choice==(CancelIndex+1))return;                
			try{(*Action[Choice-1])();}
			catch(...){}
			system("cls");
			Choice = 1;
			break;

		case char(27):
			if ((CancelIndex+1)==ItemCount)return;
			try{(*Action[ItemCount-1])();}
			catch(...){}
			Choice = 1;
			break;
Education is what remains after one has forgotten what one has learned in school.
AddThis Social Bookmark Button
Reply With Quote  
Join Date: Sep 2004
Posts: 6,507
Reputation: Narue has much to be proud of Narue has much to be proud of Narue has much to be proud of Narue has much to be proud of Narue has much to be proud of Narue has much to be proud of Narue has much to be proud of Narue has much to be proud of Narue has much to be proud of Narue has much to be proud of 
Rep Power: 31
Solved Threads: 487
Super Moderator
Narue's Avatar
Narue Narue is offline Offline
Expert Meanie

Re: New to try/catch

  #2  
Dec 5th, 2007
>Can someone please explain to me just exactly this try/catch is doing?
It's swallowing errors, basically ignoring them.
I'm here to prove you wrong.
Reply With Quote  
Join Date: Mar 2007
Location: Petoskey, Mi
Posts: 38
Reputation: spankyg is an unknown quantity at this point 
Rep Power: 2
Solved Threads: 0
spankyg's Avatar
spankyg spankyg is offline Offline
Light Poster

Re: New to try/catch

  #3  
Dec 5th, 2007
Is there really any reason to have in the code, or is this just a half-hearted attempt at trying to error detection?
Education is what remains after one has forgotten what one has learned in school.
Reply With Quote  
Join Date: Sep 2004
Posts: 6,507
Reputation: Narue has much to be proud of Narue has much to be proud of Narue has much to be proud of Narue has much to be proud of Narue has much to be proud of Narue has much to be proud of Narue has much to be proud of Narue has much to be proud of Narue has much to be proud of Narue has much to be proud of 
Rep Power: 31
Solved Threads: 487
Super Moderator
Narue's Avatar
Narue Narue is offline Offline
Expert Meanie

Re: New to try/catch

  #4  
Dec 5th, 2007
Well, it has a legitimate purpose. The author probably didn't want exceptions to propagate beyond this scope. Without the catch, the unhandled exception would just go on until it hits the first catch or until it goes all the way out of the call stack, in which case the terminate function is called.

I'm not a fan of swallowing exceptions silently (at the very least it should be logged), but I wouldn't call it half-hearted either.
I'm here to prove you wrong.
Reply With Quote  
Join Date: Mar 2007
Location: Petoskey, Mi
Posts: 38
Reputation: spankyg is an unknown quantity at this point 
Rep Power: 2
Solved Threads: 0
spankyg's Avatar
spankyg spankyg is offline Offline
Light Poster

Re: New to try/catch

  #5  
Dec 5th, 2007
Thank you, that makes a lot of sense. I understand whats try to be acheived by using
this.
Education is what remains after one has forgotten what one has learned in school.
Reply With Quote  
Reply

Only community members can participate in forum threads. You must register or log in to contribute.

DaniWeb C++ Marketplace
Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)

 

Thread Tools Display Modes

Similar Threads
Other Threads in the C++ Forum

All times are GMT -4. The time now is 9:29 am.
Forum system based on vBulletin Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
©2003 - 2008 DaniWeb® LLC