Introduction
Currently, PHP requires a block body for catch clauses even when the caught
exception is not used. This results in unnecessary boilerplate code. This
RFC proposes allowing catch clauses without a body when the exception
variable is omitted.
Proposal
Allow the following syntax where the curly braces can be omitted when no
exception variable is specified and no handling is needed:
try {
// code that may throw
} catch (SomeError);
This would be equivalent to:
try {
// code that may throw
} catch (SomeError) {}
Motivation
Reduced Boilerplate: Eliminates unnecessary empty blocks when exceptions
only need to be caught and ignored.
Improved Readability: Makes the code more concise and focuses on the
important parts.
Backward Incompatible Changes
None. This is purely an additive change to the syntax.