Friendly exception

The concept of “friendly exception” is that one can implement FriendlyExceptionInterface and provide a possible solution to the problem exception represents. Error handler may display it along with usual exception information.

Initially it was part of yii-web package that already has an error handler capable of displaying it but thinking about it for a few days I realized that it’s both useful for console applications and usage outside of Yii.

Thus, I’ve extracted a really small package with an interface only:

What do you think about it?


Why this package/repository is named friendlyexception instead of friendly-exception?

Because namespace is FriendlyException and not Friendly\Exception. See

This does not seems to be consequent ( or nor practical (ignoring words separators makes package name harder to read).

These two were not touched yet so namespaces aren’t corrected. We can come up with another naming schema. If you have an idea, please propose.

I’m not sure if creating direct relation between namespace and package name is a good idea (small change in namespace would require creating another package, and sometimes it will force creating longer namespaces or unnatural package names). But I’m definitely sure that ignoring words separators is a bad idea. Both Yiisoft\FooBar\Baz and Yiisoft\Foo\BarBaz should result foo-bar-baz as package name. Although theoretically this may create some conflicts, I doubt it will be a real problem.


I think it crude useless package.

  1. What is the need to that interface? Why Exception::getMessage() don’t you satisfied?
  2. Why a package has name FriendlyExceptionInterface instead of SolutionProvidedExceptionInterface/SolutionableInterface/etc.?
  3. What is the need to separating from core framework repository?

Because getMessage() is used not only to display purpose but for logging as well. Logging messages with solutions will make your log very bloated.

Because interface includes getName() as well. It was SolutionProviderInterface before.

Because exceptions may originate from non-core. For example, cache or RBAC.

Package was renamed to yiisoft/friendly-exception.

1 Like

Have you thought about using Whoops as the default error handler?

Yes, I did. It doesn’t bring much to the table while missing some features.