redirect inside try/catch block – bug?

5 years ago

Budry
Member | 88
+
0
-

Hi,
I found strange behavior if I catching redirect()
I have two codes

public function adctionDefault()
{
    $this->redirect('Sign:');
}
public function adctionDefault()
{
    try {
        $this->redirect('Sign:');
    } catch (\Exception $e) {
        dump($e);
        die();
    }
}

First redirect is correct but twice return Nette\AbortException. Why?
This is bug or expected behavior?

5 years ago

Majkl578
Moderator | 1379
+
0
-

Feature, redirect throws an exception (presenter run is exception-driven in this case).

public function adctionDefault()
{
    try {
        $this->redirect('Sign:');
    } catch (Nette\Application\AbortException $e) {
        throw $e;
    } catch (\Exception $e) {
        dump($e);
        die();
    }
}

5 years ago

Budry
Member | 88
+
0
-

Thanks for explaining

4 years ago

honos
Member | 109
+
0
-

@Budry Inheritance? :o)