exception handling [modified]
-
hello i want to catch divide by zero and bad pointer exception how i can do it ? why these codes don't work?
//in the name of Allah #include<iostream> #include<csetjmp> #include<stdexcept> using namespace std; int main(){ int a=0; int b; try{ b=12/a; } catch(...){ cout<<"an exception acurred :"<<endl; b=12; } }``#include<iostream> #include<stdexcept> using namespace std; int main(){ int *r; try{ if(r[0]=23) ; } catch(std::exception &e){ cout<<"error"<<endl; } }
modified on Sunday, November 7, 2010 2:57 PM
-
hello i want to catch divide by zero and bad pointer exception how i can do it ? why these codes don't work?
//in the name of Allah #include<iostream> #include<csetjmp> #include<stdexcept> using namespace std; int main(){ int a=0; int b; try{ b=12/a; } catch(...){ cout<<"an exception acurred :"<<endl; b=12; } }``#include<iostream> #include<stdexcept> using namespace std; int main(){ int *r; try{ if(r[0]=23) ; } catch(std::exception &e){ cout<<"error"<<endl; } }
modified on Sunday, November 7, 2010 2:57 PM
The
try/catch
statements are able to handle synchronous exceptions, i.e. exceptions that are explicitly thrown by the guarded code using thethrow
instruction. What you are trying to catch are asynchronous exceptions that are thrown by the microprocessor under certain conditions. What you want to do require platform specific API; on Windows systems you can do it in three different ways:- use the
__try/__except
statements (see try-except Statement (Windows)[^]) - install a vectored exception handler (see Vectored Exception Handling (Windows)[^])
- translate asynchronous exceptions to C++ (synchronous) exceptions (see /EH (Exception Handling Model) (C++)[^] and _set_se_translator (CRT)[^])
- use the
-
hello i want to catch divide by zero and bad pointer exception how i can do it ? why these codes don't work?
//in the name of Allah #include<iostream> #include<csetjmp> #include<stdexcept> using namespace std; int main(){ int a=0; int b; try{ b=12/a; } catch(...){ cout<<"an exception acurred :"<<endl; b=12; } }``#include<iostream> #include<stdexcept> using namespace std; int main(){ int *r; try{ if(r[0]=23) ; } catch(std::exception &e){ cout<<"error"<<endl; } }
modified on Sunday, November 7, 2010 2:57 PM
//in the name of Allah
#include
#include
#includeusing namespace std;
int main(){
int a=0;
int b;
try{
if(a==0)
throw "Denominator should not be zero"
b=12/a;
}
catch (const char msg[])
{
MessageBox(msg,"Exception",MB_OK | MB_ICONEXCLAMATION);
}
catch(...){
cout<<"an exception acurred :"<<;endl;
b=12;
}}
Yes U Can ...If U Can ,Dream it , U can do it ...ICAN
-
The
try/catch
statements are able to handle synchronous exceptions, i.e. exceptions that are explicitly thrown by the guarded code using thethrow
instruction. What you are trying to catch are asynchronous exceptions that are thrown by the microprocessor under certain conditions. What you want to do require platform specific API; on Windows systems you can do it in three different ways:- use the
__try/__except
statements (see try-except Statement (Windows)[^]) - install a vectored exception handler (see Vectored Exception Handling (Windows)[^])
- translate asynchronous exceptions to C++ (synchronous) exceptions (see /EH (Exception Handling Model) (C++)[^] and _set_se_translator (CRT)[^])
- use the