throwing exceptions

BobLewiston

In Runtime
Messages
182
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?
 
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.
 
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.
 
once you wrap your mind around the throw/catch blocks they are useful and powerful.
 
Back
Top Bottom