1
0

JsonException.php 894 B

12345678910111213141516171819202122232425262728293031323334353637
  1. <?php declare(strict_types=1);
  2. /**
  3. * PrivateBin
  4. *
  5. * a zero-knowledge paste bin
  6. *
  7. * @link https://github.com/PrivateBin/PrivateBin
  8. * @copyright 2012 Sébastien SAUVAGE (sebsauvage.net)
  9. * @license https://www.opensource.org/licenses/zlib-license.php The zlib/libpng License
  10. */
  11. namespace PrivateBin\Exception;
  12. use Exception;
  13. /**
  14. * JsonException
  15. *
  16. * An Exception representing JSON en- or decoding errors.
  17. */
  18. class JsonException extends Exception
  19. {
  20. /**
  21. * Exception constructor with mandatory JSON error code.
  22. *
  23. * @access public
  24. * @param int $code
  25. */
  26. public function __construct(int $code) {
  27. $message = 'A JSON error occurred';
  28. if (function_exists('json_last_error_msg')) {
  29. $message .= ': ' . json_last_error_msg();
  30. }
  31. $message .= ' (' . $code . ')';
  32. parent::__construct($message, 90);
  33. }
  34. }