PHP-Code:
<?php
class MyException extends Exception{}
?>
Den Sinn jedoch habe ich davon noch nicht verstanden. Wäre jemand vllt so freundlich mir das näherzubringen?
<?php
class MyException extends Exception{}
?>
<?PHP
class foo {
public function getStartDate($p){
try{
$r = $this->Val($p);
} catch(Exception $e) {
//Fehler behandeln
$r = new DateTime('Now');
}
return $r;
}
private function Val($p){
$r = new DateTime($p);
return $r;
}
}
$t = new foo;
$r = $t->getStartDate("Mo 1.12");
var_dump($r);
<?PHP
class foo {
public function getStartDate($p){
try{
$r = $this->Val($p);
} catch(Exception $e) {
//Fehler behandeln
$r = new DateTime('Now');
//warnung mit max.Information werfen
trigger_error((string)$e, E_USER_WARNING);
}
return $r;
}
private function Val($p){
$r = new DateTime($p);
return $r;
}
}
$t = new foo;
$r = $t->getStartDate("Mo 1.12");
var_dump($r);
WARNING exception 'Exception' with message 'DateTime::__construct() [datetime.--construct]: Failed to parse time string (Mo 1.12) at position 0 (M): The timezone could not be found in the database' in /home/phptest/public_html/code.php53(5) : eval()'d code:18 Stack trace: #0 /home/phptest/public_html/code.php53(5) : eval()'d code(18): DateTime->__construct('Mo 1.12') #1 /home/phptest/public_html/code.php53(5) : eval()'d code(6): foo->Val('Mo 1.12') #2 /home/phptest/public_html/code.php53(5) : eval()'d code(25): foo->getStartDate('Mo 1.12') #3 /home/phptest/public_html/code.php53(5): eval() #4 {main} on line number 11
try{
$r = $this->
:
} catch(Exception $e) {
throw new BarException('Fehler Methode xy');
}
class ComponentInitException extends Exception {
// public constructors etc as in Exception
}
class Component {
public function __construct() {
try {
$connect = new CONNECT($db, $user, $password, $driver, $host);
}
catch (Exception $e) {
throw new ComponentInitException($e->getMessage, $e->getCode, $e);
}
}
}
throw new Exception('Fehler class test',176);
try{
$r = $this->
:
} catch(Exception $e) {
throw new BarException('Fehler Methode xy');
}
throw new Exception('Fehler class test',176);
$code = $e->getCode();
throw $e;
throw new Exception('Fehler class test',176,$e);
try {
// ...
} catch (FooException $e) {
// Fehler in Komponente Foo
} catch (BarException $e) {
// Fehler in Komponente Bar
}
class SystemException extends Exception {}
class SystemWarningException extends Exception {}
Einen Kommentar schreiben: