Click here to Skip to main content
15,892,161 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
can we have multiple catch blocks for single try?if then how?
Posted

RTFM...
It is possible to use more than one specific catch clause in the same try-catch statement.
 
Share this answer
 
Comments
CHill60 20-May-15 5:23am    
5'd for using my favourite acronym :)
Kornfeld Eliyahu Peter 20-May-15 5:35am    
Thank you...
Andy Lanng 20-May-15 5:24am    
seconded ;)
Kornfeld Eliyahu Peter 20-May-15 5:35am    
Thank you...
Easy:
C#
private void myButton_Click(object sender, EventArgs e)
    {
    try
        {
        ...
        }
    catch (ArgumentNullException ex)
        {
        ...
        }
    catch (ArgumentOutOfRangeException ex)
        {
        ...
        }
    catch (ArgumentException ex)
        {
        ...
        }
    }
 
Share this answer
 
Comments
Kornfeld Eliyahu Peter 20-May-15 5:36am    
You forgot
catch(Exception ex) {//...}
catch(Your breath) {//...}
:-)
OriginalGriff 20-May-15 5:39am    
I don't like catch(Exception ex) much... :laugh:
And when do we get time to catch our breath round here?
Kornfeld Eliyahu Peter 20-May-15 5:42am    
My mother used to say, when we tried to get some rest in the middle of some serious work: You will have time to rest - in the grave...
Same about breath me think...

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900