mirror of
https://codeberg.org/icewind/SMB.git
synced 2026-06-04 01:34:07 +02:00
cleaner conversion of errors to exceptions
This commit is contained in:
parent
98eff3b9b8
commit
c1afd721f2
3 changed files with 55 additions and 57 deletions
|
|
@ -16,4 +16,23 @@ class Exception extends \Exception {
|
|||
|
||||
return new Exception($message, $error);
|
||||
}
|
||||
|
||||
/**
|
||||
* @param array $exceptionMap
|
||||
* @param mixed $error
|
||||
* @param string $path
|
||||
* @return Exception
|
||||
*/
|
||||
static public function fromMap(array $exceptionMap, $error, $path) {
|
||||
if (isset($exceptionMap[$error])) {
|
||||
$exceptionClass = $exceptionMap[$error];
|
||||
if (is_numeric($error)) {
|
||||
return new $exceptionClass($path, $error);
|
||||
} else {
|
||||
return new $exceptionClass($path);
|
||||
}
|
||||
} else {
|
||||
return Exception::unknown($path, $error);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue