Go Back   Computer Forums > General Computing > Programming
Join Computer forums Today

Thread Tools Search this Thread Display Modes
Old 02-03-2009, 11:25 AM   #1
Baseband Member
Join Date: Nov 2008
Posts: 91
Default throwing exceptions

The documentation I've found is a little hazy on this subject, so it's time to fire off yet another no-doubt ignorant question:

Is "throw" intended exclusively for the following scenario: Control is transferred out of a try block via a method call, and code in the called method then detects an exception, so the called method uses "throw" to transfer control back to the appropriate catch block associated with the original try block?

BobLewiston is offline   Reply With Quote
Old 02-04-2009, 07:38 AM   #2
In Runtime
Daeva's Avatar
Join Date: Dec 2005
Posts: 407
Send a message via AIM to Daeva Send a message via MSN to Daeva Send a message via Yahoo to Daeva
Default Re: throwing exceptions

Correct. Not really seeing a lot of dumb questions here.

**Official Self-proclaimed glorified excessive (insert additional adjectives here) post editor/modifier.
Edit = Best feature ever
Daeva is offline   Reply With Quote
Old 02-04-2009, 03:55 PM   #3
JogaBonito1502's Avatar
Join Date: Jan 2008
Location: U.S.
Posts: 7,841
Default Re: throwing exceptions

Yeah...I think you're correct. Throw/Catch was a hard concept to learn for me. I'm not sure why. I never use it though. It would probably be more efficient than If-Then's but I still never use it.
JogaBonito1502 is offline   Reply With Quote
Old 02-04-2009, 05:00 PM   #4
Fully Optimized
UK31337's Avatar
Join Date: Feb 2005
Posts: 2,776
Default Re: throwing exceptions

Bear in mind that exceptions are precisely that - use in exceptional situations.

You wouldn't throw an exception if you were checking if x>y but it turns out that x<y. You wouldn't use exceptions for that because it's sensible behaviour. However, if you're trying to save the result to a file and you don't have permission to access the area you're trying to save to, then that's an exceptional set of circumstances therefore throw an exception.

Sorry for the bad example, but you get the idea.
Master of common sense. If you don't like it, stop reading.
UK31337 is offline   Reply With Quote
Old 02-04-2009, 06:24 PM   #5
In Runtime
Will's Avatar
Join Date: Aug 2005
Posts: 291
Send a message via MSN to Will
Default Re: throwing exceptions

once you wrap your mind around the throw/catch blocks they are useful and powerful.
Asus M2N-SLI DELUXE mobo | XFX Geforce 9800GTX 512mb | AMD X2 4600+ | 3GB OCZ Platinum (2x512, 2x1) | 320GB WD HD + 500GB WD HD | 19" Samsung SyncMaster 931c 2ms x 2 | Creative Fatality X-Fi Sound Card |
Will is offline   Reply With Quote

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off

All times are GMT -5. The time now is 04:12 PM.

Powered by vBulletin® Version 3.8.8 Beta 4
Copyright ©2000 - 2016, vBulletin Solutions, Inc.
Search Engine Friendly URLs by vBSEO 3.6.0