Laravel and StartUp
Github
  • README
  • 개발
    • 라라벨 생태계
      • 라라벨 .env 내용을 Github Action test에 적용하기
      • 라라벨 발렛(Laravel Valet)에서 Node 실행하기
      • 라라벨 노바 훑어보기
      • 라라벨 노바의 Envoyer 배포의 실전
      • Envoyer에서 무중단 배포를 구현하는 방법
      • 라라벨이 애용하는 ::class 톺아보기
      • 라라벨에서의 버전의 의미
      • 라라벨 개발자를 위한 .aliases 파일
      • 라라벨 프로젝트를 만드는 두가지 방법 비교
    • 개발 팁
      • MySQL 9로 업데이트할 때 로그인 이슈
      • svn 저장소를 git으로 이전하기
      • CakePHP2를 PHP 8에서 쉽게 사용하기
      • 베스트 깃(Git) 커맨드
      • 퍼미션 에러없이 PHP를 구동하기 위한 서버 세팅법
      • PHP 스크립트를 php 명령어 없이 사용하는 법
      • 국제화의 필수 익스텐션, NumberFormatter
      • 라라벨에서 뷰헬퍼를 만들어 봅시다
    • 스타트업 팁
      • PHP 코딩 가이드라인
      • 배포 가이드라인
      • 기술 스택(Tech Stacks)
      • 기술 소양
      • 최신 IT 컴퍼니 트랜드
    • Knowledge Acquisition
      • Error 혹은 Warning
      • NumberFormatter class example
      • Exception + Error = Throwable Tree in PHP 7 over
      • Coding Style Preset
      • Programming Case Types
  • 협업과 비즈니스
    • 협업
      • 이메일 협업
    • 비즈니스
      • 서비스x스토어
      • 발주입고 프로세스
      • 재고월마감 프로세스
      • 재고조정 프로세스
Powered by GitBook
On this page
  • Introduction
  • Example & Output
  • ArithmeticError
  • DivisionByZeroError
  • AssertionError
  • ArgumentCountError
  • TypeError
  • Runtime Exceptions

Was this helpful?

Edit on GitHub
  1. 개발
  2. Knowledge Acquisition

Exception + Error = Throwable Tree in PHP 7 over

PreviousNumberFormatter class exampleNextCoding Style Preset

Last updated 1 year ago

Was this helpful?

Introduction

PHP 7.x introduces new Throwable interface together Error and Exception.

Interface Throwable
+-- Error
|   +-- ArithmeticError
|   |   +-- DivisionByZeroError
|   +-- AssertionError
|   +-- CompileError (PHP 7.3 over)
|       +-- ParseError
|   +-- TypeError
|       +-- ArgumentCountError
+-- Exception
    +-- ClosedGeneratorException
    +-- DOMException
    +-- ErrorException
    +-- IntlException
    +-- LogicException
    |   +-- BadFunctionCallException
    |   |   +-- BadMethodCallException
    |   +-- DomainException
    |   +-- InvalidArgumentException
    |   +-- LengthException
    |   +-- OutOfRangeException
    +-- PharException
    +-- ReflectionException
    +-- RuntimeException
        +-- mysqli_sql_exception
        +-- OutOfBoundsException
        +-- OverflowException
        +-- PDOException
        +-- RangeException
        +-- UnderflowException
        +-- UnexpectedValueException

Example & Output

ArithmeticError

<?php

intdiv(PHP_INT_MIN, -1);

// output
// Fatal error: Uncaught ArithmeticError: Division of PHP_INT_MIN by -1 is not an integer

DivisionByZeroError

<?php

$a = 3%0;

// output
// PHP Fatal error:  Uncaught DivisionByZeroError: Modulo by zero

$a = intdiv(3, 0); // 3/0 is not fire exception.

// output
// PHP Fatal error:  Uncaught DivisionByZeroError: Division by zero

AssertionError

<?php

ini_set('assert.exception', 1); //if without this, not exception but error

assert(2 < 1);

// output
// PHP Fatal error:  Uncaught AssertionError: assert(2 < 1) in...

ArgumentCountError

<?php

declare(strict_types=1); //if without this, not exception but error

$a = [1,2=>[3,4]];

count($a, COUNT_RECURSIVE, 'throw error');

// output
// PHP Fatal error:  Uncaught ArgumentCountError: count() expects at most 2 parameters, 3 given

TypeError

<?php

a('throw error');

function a(int $b) {}

// output
// PHP Fatal error:  Uncaught TypeError: Argument 1 passed to a() must be of the type int, string given

Runtime Exceptions

Name
Example

LogicException

PHP Throwable Tree
Introduction
Example & Output
ArithmeticError
DivisionByZeroError
AssertionError
ArgumentCountError
TypeError
Runtime Exceptions
LogicException.php