2016-11-09 2 views
0

Ich kann die StaleStateException von RuntimeException nicht sofort abfangen, warum? Warum das entwerfen?Ich kann die StaleStateException nicht sofort abfangen, warum?

, wenn die erste transaktionale nicht vorlegen, werde ich die Ausnahme nicht fangen, aber StaleStateException erstreckt Runtime, Zweifel, sollte es sollte es sofort fangen

public ResponseInfo catchExce() { 

    try { 
     throwExceServiceA.throwExce(); 
    } catch (StaleStateException e) { 
     System.out.println("This is a StaleStateException"); 
    } catch (Exception e) { 
     System.out.println("This is a StaleStateException. Also is catched here"); 
    } finally { 
     System.out.println("This block is always executed"); 
    } 

} 

ThrowExceServiceA

@Transactional(propagation = Propagation.REQUIRES_NEW) 
public void throwExce() throws InterruptedException { 

    throwExceServiceB.throwExce(); 
    Thread.sleep(1000); 
} 

ThrowExceServiceB

@Transactional(propagation = Propagation.REQUIRES_NEW) 
public void throwExce() { 
    throw new StaleStateException(""); 
} 
+0

Sie haben keinen Code innerhalb der Fang Ihres ersten Codeblock, sollten Sie in der Lage sein, die Ausnahme zu fangen – cralfaro

+0

Ich frage mich, warum Sie re- poste deine erste Frage. Sie haben diese andere Frage bearbeitet, warten Sie also entweder, bis sie wieder geöffnet wird, oder löschen Sie sie. – Tom

+1

@Tom Ich werde es löschen –

Antwort

0

Fügen Sie dies Ihrem Code hinzu:

public ResponseInfo catchExce() { 

    try { 
     throwExceServiceA.throwExce(); 
    } 
    catch (StaleStateException e) { 
     System.out.println("This is a StaleStateException"); 
    } 
    catch (Exception e) { 
     System.out.println("This is a StaleStateException. Also is catched here"); 
    } 
    finally{ 
     System.out.println("This block is always executed"); 
    } 
} 

Ich hoffe, dass dies ein wenig Ihre Demo klären

Verwandte Themen