Announcement

Collapse
No announcement yet.

Throw Exceptions - unexpected and terminate functions

Collapse
X
 
  • Filter
  • Time
  • Show
Clear All
new posts

  • Throw Exceptions - unexpected and terminate functions

    set_unexpected called because the function hasn't permission to throw exceptions. After, terminate function is launched.
    PHP Code:
    #include <iostream>
    #include <string>
    #include <stdexcept>


    using namespace std;

    ////////////////////////// samaple class

    class DivideForZeroException : public runtime_error {
    public:
        
    DivideForZeroException()
        : 
    runtime_error("Impossibile dividere per 0\n")
        {}
    };


    ///////////// termiante and unexpected functions


    void terminate_function(){
        
    cout << "terminate_function" << endl;
    }

    void unexpected_function(){
        
    cout << "unexpected_function" << endl;
    }



    ////////////// the function called to throw excpetion

    void function() throw(){

        try{
            throw 
    DivideForZeroException();
        }
        catch (
    DivideForZeroException  error){
            throw ;
        }

    }



    int main (void){
        
        
    set_terminate(terminate_function);
        
    set_unexpected(unexpected_function);
        
        ::function();

        return 
    0;

    | VFX Artist, C++ Programmer, HW Overclocker | Web: xgiovio.com Email: xgiovio@gmail.com Twitter: @xgiovio

  • #2
    Same version but the function can throw any exception. So the unexpected function isn't launched.
    PHP Code:
    #include <iostream>
    #include <string>
    #include <stdexcept>


    using namespace std;

    ////////////////////////// samaple class

    class DivideForZeroException : public runtime_error {
    public:
        
    DivideForZeroException()
        : 
    runtime_error("Impossibile dividere per 0\n")
        {}
    };


    ///////////// termiante and unexpected functions


    void terminate_function(){
        
    cout << "terminate_function" << endl;
    }

    void unexpected_function(){
        
    cout << "unexpected_function" << endl;
    }



    ////////////// the function called to throw excpetion

    void function() {

        try{
            throw 
    DivideForZeroException();
        }
        catch (
    DivideForZeroException  error){
            throw ;
        }

    }



    int main (void){
        
        
    set_terminate(terminate_function);
        
    set_unexpected(unexpected_function);
        
        ::function();

        return 
    0;

    | VFX Artist, C++ Programmer, HW Overclocker | Web: xgiovio.com Email: xgiovio@gmail.com Twitter: @xgiovio

    Comment


    • #3
      Originally posted by riham
      Perfect... thanks for this tip! Appreciate your response.
      No problem riham!
      | VFX Artist, C++ Programmer, HW Overclocker | Web: xgiovio.com Email: xgiovio@gmail.com Twitter: @xgiovio

      Comment


      • #4
        likes as forum
        ___________

        ahmed

        Comment


        • #5
          Originally posted by xgiovio View Post
          Same version but the function can throw any exception. So the unexpected function isn't launched.
          PHP Code:
          #include <iostream>
          #include <string>
          #include <stdexcept>


          using namespace std;

          ////////////////////////// samaple class

          class DivideForZeroException : public runtime_error {
          public:&
          #1591;راحی سایت
          DivideForZeroException()
          runtime_error("Impossibile dividere per 0\n")
          {}
          };


          ///////////// termiante and unexpected functions


          void terminate_function(){
          cout << "terminate_function" << endl;
          }

          void unexpected_function(){http://www.rahkarenovin.com/
          cout << "unexpected_function" << endl;
          }



          ////////////// the function called to throw excpetion

          void function() {

          try{
          throw 
          DivideForZeroException();
          }
          catch (
          DivideForZeroException error){
          throw ;
          http://www.rahkarenovin.net/
          }

          }



          int main (void){

          set_terminate(terminate_function);
          set_unexpected(unexpected_function);

          ::function();

          return 
          0;





          Hello
          this functions do not work on PHP 7 version
          please guide me
          thanks
          Last edited by siavash82ir; 07-27-2019, 05:02 PM.

          Comment

          Working...
          X

          Google Profile


          My name is Giovanni Di Grezia, but people call me xgiovio.

          Here is my homepage:.

          I'm a VFX Artist and Software Developer.

          Giovanni Di Grezia