Skip to content

Instantly share code, notes, and snippets.

@yuyu-TZ321
Created September 4, 2017 15:17
Show Gist options
  • Save yuyu-TZ321/fc8d9b083681aa7b1cafa5c307bcf6fc to your computer and use it in GitHub Desktop.
Save yuyu-TZ321/fc8d9b083681aa7b1cafa5c307bcf6fc to your computer and use it in GitHub Desktop.
<?php
class Debug
{
public function getTest($x)
{
if ( !is_numeric($x) ) {
throw new Exception('This not number');
}
return $x;
}
}
class YuException extends Exception
{
public function errorMessage()
{
$errorMsg = 'Message: '.$this->getMessage();
return $errorMsg;
}
}
class DebugTwo
{
public function getTest($x)
{
if ( !is_numeric($x) ) {
throw new YuException('This not number');
}
return $x;
}
}
$Debug = new Debug();
try {
echo $Debug->getTest('1') . "\r\n";
echo $Debug->getTest('A') . "\r\n";
echo $Debug->getTest(0) . "\r\n";
} catch (Exception $e) {
echo $e->getMessage()."\r\n";
}
$DebugTwo = new DebugTwo();
try {
echo $DebugTwo->getTest('1') . "\r\n";
echo $DebugTwo->getTest('A') . "\r\n";
echo $DebugTwo->getTest(0) . "\r\n";
} catch (YuException $e) {
echo $e->errorMessage()."\r\n";
}
@dinos80152
Copy link

$Debug = new Debug();
$DebugTwo = new DebugTwo();
try {
    echo $Debug->getTest('1') . "\r\n";
    echo $Debug->getTest('A') . "\r\n";
    echo $Debug->getTest(0) . "\r\n";
    echo $DebugTwo->getTest('1') . "\r\n";
    echo $DebugTwo->getTest('A') . "\r\n";
    echo $DebugTwo->getTest(0) . "\r\n";
} catch (YuException $e) {
    echo $e->getMessage()."\r\n";
} catch (Exception $e) {
    echo $e->getMessage()."\r\n";
} finally {
    echo "finish";
}

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment