«   2018/09   »
            1
2 3 4 5 6 7 8
9 10 11 12 13 14 15
16 17 18 19 20 21 22
23 24 25 26 27 28 29
30            
Archives
Today
47
Total
1,153,564
안정적인 DNS서비스 DNSEver
관리 메뉴

Blue Breeze

php7.1 Catching Multiple Exception Types 본문

Language/PHP

php7.1 Catching Multiple Exception Types

푸른바람 C/H 2017.05.31 08:30

try {
   // Some code...
} catch (ExceptionType1 $e) {
   // Code to handle the exception
} catch (ExceptionType2 $e) {
   // Same code to handle the exception
} catch (Exception $e) {
   // ...
}
try {
   // Some code...
} catch (ExceptionType1 | ExceptionType2 $e) {
   // Code to handle the exception
} catch (\Exception $e) {
   // ...
}
class exept1 extends Exception
{
	function __construct($message, $code = 0, Exception $previous = null)
	{
		parent::__construct($message, $code, $previous);
	}
}

class exept2 extends Exception
{
	function __construct($message, $code = 0, Exception $previous = null)
	{
		parent::__construct($message, $code, $previous);
	}
}

try
{
	if($rand = 1){
		throw new exept1(123);
	}else{
		throw new exept2(143);
	}
}
catch(exept1 | exept2 $e)
{
	var_dump( $e );
}


'Language > PHP' 카테고리의 다른 글

Yii model get query  (0) 2017.08.25
PHP math-php  (0) 2017.06.01
php7.1 Catching Multiple Exception Types  (0) 2017.05.31
brew php-xdebug  (0) 2017.05.29
Multi-library chart PHP  (0) 2017.05.26
botman PHP  (0) 2017.05.25
0 Comments
댓글쓰기 폼