Hi anyone.
In your opinion I can use try
and catch in this way I mean
it works but there is a better way
to put it within the classes and overall
it is a good way?
Could you help me ?
I'd like to get on my php5 speaking 😃
Here the code is:
<?php
class TEWrongPathException extends Exception
{
public function construct($path)
{
parent::construct("The path : {$path} doesn't exit or is wrong");
}
}
class doSomething
{
private $defaultPath;
public function construct()
{
$this->defaultPath = './';
}
public function SetDefaultPath($path)
{
// Verifica se il percorso esiste
try {
if (file_exists($path) === true)
{
// Imposta il percorso
$this->defaultPath = $path;
}
else
{
throw new TEWrongPathException($path);
}
}
catch (TEWrongPathException $e) {
print $e->getMessage();
}
}
}
$wrongPath = "wrongPath/file.php";
$o = new doSomething();
$o->SetDefaultPath($wrongPath);
?>
Take care.