Announcement

Collapse
No announcement yet.

Throw Exceptions - unexpected and terminate functions

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

  • siavash82ir
    replied
    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.

    Leave a comment:


  • ahmedvu153
    replied
    likes as forum
    ___________

    ahmed

    Leave a comment:


  • xgiovio
    replied
    Originally posted by riham
    Perfect... thanks for this tip! Appreciate your response.
    No problem riham!

    Leave a comment:


  • xgiovio
    replied
    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;

    Leave a comment:


  • xgiovio
    started a topic Throw Exceptions - unexpected and terminate functions

    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;

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