Click here to Skip to main content
15,904,415 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Helo guys
I am relatively familiar with native cpp but never used exception handling.
Now I want help to understand how can I catch exceptions like this
C++
try
{
    int p = 0;
    int q = 0;
    int r = p / q;//divide by zero exception
}
catch (???)//what should I write here instead of ????
{
    .....
}

C++
try
{
    int * p = 0;
    * p = 0;
}
catch (???)//what should I write here instead of ????
{
}
Any suggestion about how to find usefull articles is appreciated
Thanks in advanmce
mr.abzadeh

appended by mr.abzadeh:I have found that divide by zero and access violation exceptions are not handled thru try {} catch {} mecanism. I think the catch block catches exections explicitly thrown by programmer.
Now my question is:
Is there any mechanism to catch exceptions like integer divide by zero and access violation in native c++?
Posted
Updated 6-Oct-11 4:44am
v5

1 solution

Exception handling is as follows:

C#
try
{
 // risky code
}
catch(Excetpion_Name& ex)
{
 // handle here
}


You can catch all exceptions regardless their type with:

C#
catch(...)
{

}
 
Share this answer
 
Comments
mr.abzadeh 6-Oct-11 10:28am    
You have mentioned my question, no responce is given.
My question is: what to write in cache clause?
Can you please show me a clear example that catches divide by zero?
Thanks

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