By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
435,255 Members | 2,575 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 435,255 IT Pros & Developers. It's quick & easy.

throwing exceptions

P: 93
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?
Feb 3 '09 #1
Share this Question
Share on Google+
1 Reply


Plater
Expert 5K+
P: 7,872
I'm not sure what you question is exactly.
"throw (some exception)" will just raise an exception on the thread it was called on. where it gets "caught" is up to you.

What I have seen people do, in their own classes, is catch all possible exceptions and then re-throw an instance of their own exception. To sort of "hide" the exceptions.

Expand|Select|Wrap|Line Numbers
  1. public void ParseParam(string param)
  2. {
  3.    try
  4.    {
  5.       //some parsing code that could cause an exception
  6.    }
  7.    catch(Exception ee)
  8.    {
  9.        throw new MyCustomExceptionType("Please pass in a valid value for param");
  10.    }
  11. }
  12.  
Feb 3 '09 #2

Post your reply

Sign in to post your reply or Sign up for a free account.