website/errors/catch.internalClass.md
<?php declare(strict_types = 1);
namespace Vendor {
/** @internal */
class InternalException extends \Exception {}
}
namespace App {
function doFoo(): void
{
try {
throw new \Exception();
} catch (\Vendor\InternalException $e) {
}
}
}
A catch block is catching an exception class that is marked as @internal. Internal classes are not meant to be used outside of the package or namespace where they are defined. Catching internal exceptions creates a dependency on implementation details that may change without notice in future versions.
Catch a public (non-internal) parent exception class instead:
try {
throw new \Exception();
-} catch (\Vendor\InternalException $e) {
+} catch (\RuntimeException $e) {
}
If the library provides a public exception class or interface for this purpose, catch that instead.