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.if (file_exists($path) !== true) throw new TEWrongPathException($path);
is the proper way to goTks a lot buddy sound better
Bye.
You know little by little .................
Tks againPlease indent your code. It makes things a lot easier for those reading your post and for you.Hi.
Tks for the piece of advice I promise
to indent the code
and TKS a lot for the new link
in the back OOP 5 very useful.
Take care.
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.if (file_exists($path) !== true) throw new TEWrongPathException($path);
is the proper way to goTks a lot buddy sound better
Bye.
You know little by little .................
Tks againPlease indent your code. It makes things a lot easier for those reading your post and for you.Hi.
Tks for the piece of advice I promise
to indent the code
and TKS a lot for the new link
in the back OOP 5 very useful.
Take care.