# Exception + Error = Throwable Tree in PHP 7 over

* [PHP Throwable Tree](#php-throwable-tree)
  * [Introduction](#introduction)
  * [Example & Output](#example--output)
    * [ArithmeticError](#arithmeticerror)
    * [DivisionByZeroError](#divisionbyzeroerror)
    * [AssertionError](#assertionerror)
    * [ArgumentCountError](#argumentcounterror)
    * [TypeError](#typeerror)
  * [Runtime Exceptions](#runtime-exceptions)

## Introduction

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

```bash
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
<?php

intdiv(PHP_INT_MIN, -1);

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

### DivisionByZeroError

```php
<?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
<?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
<?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
<?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 | [LogicException.php](https://github.com/cable8mm/laravel-tips/blob/main/src/ThrowableTree/LogicException.php) |


---

# Agent Instructions: Querying This Documentation

If you need additional information that is not directly available in this page, you can query the documentation dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter:

```
GET https://laravel.palgle.com/knowledge-acquisition/throwable-tree.md?ask=<question>
```

The question should be specific, self-contained, and written in natural language.
The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
