1
0

JsonException.php 898 B

1234567891011121314151617181920212223242526272829303132333435363738
  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. {
  28. $message = 'A JSON error occurred';
  29. if (function_exists('json_last_error_msg')) {
  30. $message .= ': ' . json_last_error_msg();
  31. }
  32. $message .= ' (' . $code . ')';
  33. parent::__construct($message, 90);
  34. }
  35. }