PHP 8.5.0 Beta 3 available for testing

Exception

(PHP 5, PHP 7, PHP 8)

ใฏใ˜ใ‚ใซ

Exception ใฏใ€ ใ™ในใฆใฎใƒฆใƒผใ‚ถใƒผไพ‹ๅค–ใฎๅŸบๅบ•ใ‚ฏใƒฉใ‚นใงใ™ใ€‚

ใ‚ฏใƒฉใ‚นๆฆ‚่ฆ

class Exception implements Throwable {
/* ใƒ—ใƒญใƒ‘ใƒ†ใ‚ฃ */
protected string $message = "";
private string $string = "";
protected int $code;
protected string $file = "";
protected int $line;
private array $trace = [];
private ?Throwable $previous = null;
/* ใƒกใ‚ฝใƒƒใƒ‰ */
public __construct(string $message = "", int $code = 0, ?Throwable $previous = null)
final public getMessage(): string
final public getPrevious(): ?Throwable
final public getCode(): int
final public getFile(): string
final public getLine(): int
final public getTrace(): array
final public getTraceAsString(): string
public __toString(): string
private __clone(): void
}

ใƒ—ใƒญใƒ‘ใƒ†ใ‚ฃ

message

ไพ‹ๅค–ใƒกใƒƒใ‚ปใƒผใ‚ธ

code

ไพ‹ๅค–ใ‚ณใƒผใƒ‰

file

ไพ‹ๅค–ใŒไฝœใ‚‰ใ‚ŒใŸใƒ•ใ‚กใ‚คใƒซๅ

line

ไพ‹ๅค–ใŒไฝœใ‚‰ใ‚ŒใŸ่กŒ

previous

็›ดๅ‰ใซใ‚นใƒญใƒผใ•ใ‚ŒใŸไพ‹ๅค–

string

ใ‚นใ‚ฟใƒƒใ‚ฏใƒˆใƒฌใƒผใ‚นใ‚’็คบใ™ๆ–‡ๅญ—ๅˆ—

trace

ใ‚นใ‚ฟใƒƒใ‚ฏใƒˆใƒฌใƒผใ‚นใ‚’็คบใ™้…ๅˆ—

็›ฎๆฌก

  • Exception::__construct โ€” ไพ‹ๅค–ใ‚’ไฝœๆˆใ™ใ‚‹
  • Exception::getMessage โ€” ไพ‹ๅค–ใƒกใƒƒใ‚ปใƒผใ‚ธใ‚’ๅ–ๅพ—ใ™ใ‚‹
  • Exception::getPrevious โ€” ๅ‰ใฎไพ‹ๅค–(Throwable)ใ‚’่ฟ”ใ™
  • Exception::getCode โ€” ไพ‹ๅค–ใ‚ณใƒผใƒ‰ใ‚’ๅ–ๅพ—ใ™ใ‚‹
  • Exception::getFile โ€” ไพ‹ๅค–ใŒไฝœใ‚‰ใ‚ŒใŸใƒ•ใ‚กใ‚คใƒซใ‚’ๅ–ๅพ—ใ™ใ‚‹
  • Exception::getLine โ€” ไพ‹ๅค–ใŒไฝœใ‚‰ใ‚ŒใŸ่กŒใ‚’ๅ–ๅพ—ใ™ใ‚‹
  • Exception::getTrace โ€” ใ‚นใ‚ฟใƒƒใ‚ฏใƒˆใƒฌใƒผใ‚นใ‚’ๅ–ๅพ—ใ™ใ‚‹
  • Exception::getTraceAsString โ€” ใ‚นใ‚ฟใƒƒใ‚ฏใƒˆใƒฌใƒผใ‚นใ‚’ๆ–‡ๅญ—ๅˆ—ใงๅ–ๅพ—ใ™ใ‚‹
  • Exception::__toString โ€” ไพ‹ๅค–ใฎๆ–‡ๅญ—ๅˆ—่กจ็พ
  • Exception::__clone โ€” ไพ‹ๅค–ใ‚’ใ‚ณใƒ”ใƒผใ™ใ‚‹
๏ผ‹add a note

User Contributed Notes 3 notes

up
103
whysteepy at gmail dot com ยถ
7 years ago
Lists of Throwable and Exception tree as of 7.2.0

Error
ArithmeticError
DivisionByZeroError
AssertionError
ParseError
TypeError
ArgumentCountError
Exception
ClosedGeneratorException
DOMException
ErrorException
IntlException
LogicException
BadFunctionCallException
BadMethodCallException
DomainException
InvalidArgumentException
LengthException
OutOfRangeException
PharException
ReflectionException
RuntimeException
OutOfBoundsException
OverflowException
PDOException
RangeException
UnderflowException
UnexpectedValueException
SodiumException

Find the script and output in the following links:
https://gist.github.com/mlocati/249f07b074a0de339d4d1ca980848e6a
https://3v4l.org/sDMsv

posted by someone here http://php.net/manual/en/class.throwable.php
up
32
cHao ยถ
10 years ago
Note that an exception's properties are populated when the exception is *created*, not when it is thrown. Throwing the exception does not seem to modify them.

Among other things, this means:

* The exception will blame the line that created it, not the line that threw it.

* Unlike in some other languages, rethrowing an exception doesn't muck up the trace.

* A thrown exception and an unthrown one look basically identical. On my machine, the only visible difference is that a thrown exception has an `xdebug_message` property while an unthrown one doesn't. Of course, if you don't have xdebug installed, you won't even get that.
up
7
shaman_master at list dot ru ยถ
5 years ago
Note: this documentation not full, ReflectionObject::export($exception):
<?php
Object of
class [ class Exception implements Throwable ] {
-
Properties [7] {
Property [ protected $message ]
Property [ private $string ]
Property [ protected $code ]
Property [ protected $file ]
Property [ protected $line ]
Property [ private $trace ]
Property [ private $previous ]
}
-
Methods [11] {
Method [ final private method __clone ] {
}

Method [ public method __construct ] {

-
Parameters [3] {
Parameter #0 [ $message ]
Parameter #1 [ $code ]
Parameter #2 [ $previous ]
}
}

Method [ public method __wakeup ] {
}

Method [ final public method getMessage ] {
}

Method [ final public method getCode ] {
}

Method [ final public method getFile ] {
}

Method [ final public method getLine ] {
}

Method [ final public method getTrace ] {
}

Method [ final public method getPrevious ] {
}

Method [ final public method getTraceAsString ] {
}

Method [ public method __toString ] {
}
}
}
?>

Missed:

Property [ private $string ]
Property [ private $trace ]
Property [ private $previous ]

Method [ public method __wakeup ] {
}
To Top