Custom exceptions

Edit on GitHub

When you need to throw an exception, you need to define your own type of exception. Later, it is much easier to handle exceptions when the type represents a specific type of error.

In Spryker exceptions and errors are handled in a central error handler that will stop the execution. Do not use exceptions as events to control the workflow. Only expected exceptions are caught—for example, when you deal with external systems, or when you must guarantee the execution—for example, when you send an email in the checkout then this must not break the execution.

Usually, exceptions have an empty body and extend the global \Exception class.

<?php

namespace Pyz\Zed\Glossary\Business\Exception;

use Exception;

class KeyExistsException extends Exception
{
}