1<?php
2
3namespace dokuwiki\plugin\extension;
4
5use Throwable;
6
7/**
8 * Implements translatable exception messages
9 */
10class Exception extends \Exception
11{
12    /**
13     * @param string $message The error message or language string
14     * @param array $context array of sprintf variables to be replaced in the message
15     * @param Throwable|null $previous Previous exception
16     */
17    public function __construct($message = "", $context = [], Throwable $previous = null)
18    {
19        // try to translate the message
20        $helper = plugin_load('helper', 'extension');
21        $newmessage = $helper->getLang($message);
22        if ($newmessage === '') {
23            $newmessage = $message;
24        }
25
26        if ($context) {
27            $newmessage = vsprintf($newmessage, $context);
28        }
29
30        parent::__construct($newmessage, 0, $previous);
31    }
32}
33