Skip to content

Instantly share code, notes, and snippets.

@dozer111
Created February 3, 2022 08:34
Show Gist options
  • Save dozer111/c28e842e96b2273bd2446ceaa13809cf to your computer and use it in GitHub Desktop.
Save dozer111/c28e842e96b2273bd2446ceaa13809cf to your computer and use it in GitHub Desktop.

1 перевыброс ошибки работает, если это просто код

    
try{
    
echo "Try |";
throw new \Exception('tst');
}catch(\Throwable $t)
{
    echo "catch |";
    throw new \Exception('asdasdasdasd');
    
}finally{
    echo "finally";
}

2 если этот же код в методе c return, то перевыброса не будет

function test(){
    

try{
    
echo "Try |";
throw new \Exception('tst');
}catch(\Throwable $t)
{
    echo "catch |";
    throw new \Exception('asdasdasdasd');
    
}finally{
    echo "finally";
    return 2;
}
}

echo test();

заставляем ф-ю таки выбросить исключение

function test(){
    
$throwException = fn() => 0;
try{
    
echo "Try |";
throw new \Exception('tst');
}catch(\Throwable $t)
{
    $throwException = function(){
        throw new \Exception('asdasdasdasd');
    };
    echo "catch |";
    throw new \Exception('asdasdasdasd');
    
}finally{
    echo "finally";
    $throwException();
    return 2;
}
}

echo test();
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment