[multi-threading] exceptions



  • Hallo
    Ich benutze boost threads. Nun habe ich das das Problem, dass ich die in nem zweiten Thread ausgelösten Exceptions gerne in der thread-erzeugenden Klasse auffangen möchte. Derzeit verwenden wir eigene von std::exception abgeleitete excpetions.

    class Calculator{
    public:
    ...
    void calculate() { for(;;) {/*blabla*/ throw UbException("AAARGH"}; } }
    ...
    };
    class Hauptklasse{
    public:
    ...
    };
    
    void starteBerechnung()
    {
        thrd = boost::shared_ptr<boost::thread>(new boost::thread(boost::bind(&Calculator::calculate, &calculator) ) );
    }
    protected:
    Calculator calculator;
    boost::shared_ptr<boost.thread> thrd;
    };
    

    In der main ist dann der Haupt try-catch Block.
    Die exception aus Calculator::calculate wird leider nicht abgefangen.
    Muss man evtl in diesem Fall die Exception Klasse von boost verwenden?

    soeben habe das hier gefunden:

    "... When an exception is thrown and there is no matching exception handler in the same thread, behavior is undefined. The preferred behavior is the same as when there is no matching exception handler in a program [15.3/9]. That is, terminate() is called, and it is implementation-defined whether or not the stack is unwound. ..."
    Quelle: http://www.boost.org/doc/html/threads.html

    gibt es da wirklich keine möglichkeit???



  • Hi,

    ich glaube, da es in der Freiheit jedes Compilerherstellers liegt, wie er exceptions technisch handhabt, wird es da wohl keinen standardisierten Weg geben.

    Einzige Möglichkeit, die mir einfällt: Im werfenden Thread fangen und über normale "Interthreadkommunikation" dem Anderen mitteilen.

    Nachtrag: was erwartest Du eigentlich, dass der Hauptthread tun soll, wenn die exception im Nebenthread fliegt ? Der Hauptthread tut ja auch gerade etwas ... soll er das sofort unterbrechen ? Auch wenn er noch keinen try-Block erreicht hat ? Ich glaube, das ist konzeptionell noch etwas nicht ganz im Reinen bei Dir.

    Gruß,

    Simon2.


Anmelden zum Antworten