'Serenity BDD exception handling

Hello I am currently implementing some tests on Serenity BDD (2.52.0) and with JUnit 4 (4.13.1). I have test which has a situational step based on some conditions , when I try to execute the test with the optional part surrounded by try , catch the exception in caught but the test still sees it as a failure.

Example :

@Test
public void test1(){
    try {
        myStep.doSomething();
    }catch (Exception e) {
        System.out.println("caught");
        myStep.doSomethingElse();
    }
}

And let's say the steps are the following

@Step
public void doSomething() throws Exception {
    int k = 3/0;
}

@Step
public void doSomethingElse() {
    int k = 3/1;
}

On execution I get the following error

[main] ERROR  -     Test failed at step: Do something
[main] ERROR  -     / by zero

So basically I want to be able to try execute "doSomething()" and should that fail execute the other method without making the test appear as a failed one



Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source