website/errors/catch.internalTrait.md
<?php declare(strict_types = 1);
namespace Vendor {
/** @internal */
trait SomeInternalTrait {}
class Foo {
use SomeInternalTrait;
}
}
namespace App {
function doFoo(): void
{
try {
throw new \Exception();
} catch (\Vendor\SomeInternalTrait $e) {
}
}
}
A catch block references a trait that is marked as @internal. Internal types are not meant to be used outside of the package or namespace where they are defined. Catching internal types creates a dependency on implementation details that may change without notice in future versions.
Traits are not throwable, so catching a trait in a catch block is invalid regardless of the @internal annotation.
Catch a public (non-internal) exception class instead:
try {
throw new \Exception();
-} catch (\Vendor\SomeInternalTrait $e) {
+} catch (\RuntimeException $e) {
}