Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
  1. Home
  2. General Programming
  3. ATL / WTL / STL
  4. exception handling [modified]

exception handling [modified]

Scheduled Pinned Locked Moved ATL / WTL / STL
helpquestion
4 Posts 3 Posters 1 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • K Offline
    K Offline
    khomeyni
    wrote on last edited by
    #1

    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

    S S 2 Replies Last reply
    0
    • K khomeyni

      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

      S Offline
      S Offline
      Sauro Viti
      wrote on last edited by
      #2

      The try/catch statements are able to handle synchronous exceptions, i.e. exceptions that are explicitly thrown by the guarded code using the throw 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:

      1. use the __try/__except statements (see try-except Statement (Windows)[^])
      2. install a vectored exception handler (see Vectored Exception Handling (Windows)[^])
      3. translate asynchronous exceptions to C++ (synchronous) exceptions (see /EH (Exception Handling Model) (C++)[^] and _set_se_translator (CRT)[^])
      K 1 Reply Last reply
      0
      • K khomeyni

        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

        S Offline
        S Offline
        ShilpiP
        wrote on last edited by
        #3

        //in the name of Allah
        #include
        #include
        #include

        using 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

        1 Reply Last reply
        0
        • S Sauro Viti

          The try/catch statements are able to handle synchronous exceptions, i.e. exceptions that are explicitly thrown by the guarded code using the throw 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:

          1. use the __try/__except statements (see try-except Statement (Windows)[^])
          2. install a vectored exception handler (see Vectored Exception Handling (Windows)[^])
          3. translate asynchronous exceptions to C++ (synchronous) exceptions (see /EH (Exception Handling Model) (C++)[^] and _set_se_translator (CRT)[^])
          K Offline
          K Offline
          khomeyni
          wrote on last edited by
          #4

          ok thanks a lot.do you know how to do it in linux(fedora?)

          1 Reply Last reply
          0
          Reply
          • Reply as topic
          Log in to reply
          • Oldest to Newest
          • Newest to Oldest
          • Most Votes


          • Login

          • Don't have an account? Register

          • Login or register to search.
          • First post
            Last post
          0
          • Categories
          • Recent
          • Tags
          • Popular
          • World
          • Users
          • Groups