Throw



  • Kann mir mal einer sagen wieso der 2.Catch Block nicht angesteuert wird obwohl ich die Exception aus Catch Block 1 nochmal werfe ? Ich erinnere mich C++ war das glaub ich so dass wenn ein darunterliegender catch Block die Exception fangen kann dann fängt er sie auch.

    try
    			{
    				throw varEx1;
    			}
    			catch( KException varEx)
    			{
    				int zzuu ;
    				zzuu = 3;
    				throw varEx; // hier neu werfen
    			}
    			catch(Exception adf)
    			{
    				int z;
    				z = 3;
    			}
    


  • Javaner19 schrieb:

    Kann mir mal einer sagen wieso der 2.Catch Block nicht angesteuert wird obwohl ich die Exception aus Catch Block 1 nochmal werfe ?

    Weil der Kontrollfluss den try Block, mit dem das catch assoziiert ist, schon verlassen hat.

    Javaner19 schrieb:

    Ich erinnere mich C++ war das glaub ich so dass wenn ein darunterliegender catch Block die Exception fangen kann dann fängt er sie auch.

    Nope



  • Das bedeutet ein rethrow steuert niemals ein anderes catch an sondern wird immer an die aufrufende Funktion weitergereicht.



  • Zumindest in C++, Ja...

    N4527 §15.1/2 schrieb:

    When an exception is thrown, control is transferred to the nearest handler with a matching type (15.3); “nearest” means the handler for which the compound-statement or ctor-initializer following the try keyword was most recently entered by the thread of control and not yet exited.



  • asdfrr schrieb:

    Das bedeutet ein rethrow steuert niemals ein anderes catch an sondern wird immer an die aufrufende Funktion weitergereicht.

    Falsch. Du musst halt nur ein weiteres try{}catch{} um die ganze Konstruktion rum machen.


Anmelden zum Antworten