PHP.mk документација

Exception::getCode

Почист и полокален преглед на PHP референцата, со задржана структура од PHP.net и подобра читливост за примери, секции и белешки.

exception.getcode.php PHP.net прокси Преводот се освежува
Оригинал на PHP.net
Патека exception.getcode.php Локална патека за оваа страница.
Извор php.net/manual/en Оригиналниот HTML се реупотребува и локално се стилизира.
Режим Прокси + превод во позадина Кодовите, табелите и белешките остануваат читливи во истиот тек.
Exception::getCode

Референца за `exception.getcode.php` со подобрена типографија и навигација.

exception.getcode.php

Exception::getCode

класата mysqli_driver

Exception::getCodeЈа добива шифрата на исклучокот

= NULL

final public Exception::getCode(): int

Враќа шифра на исклучокот.

Параметри

Оваа функција нема параметри.

Вратени вредности

Враќа шифра на исклучокот како int in Исклучок но можно како друг тип во Исклучок потомци (на пример како string in PDOException).

Примери

Пример #1 (PHP 5 >= 5.1.0, PHP 7, PHP 8) example

<?php
try {
throw new
Exception("Some error message", 30);
} catch(
Exception $e) {
echo
"The exception code is: " . $e->getCode();
}
?>

Горниот пример ќе прикаже нешто слично на:

The exception code is: 30

Види Исто така

Белешки од корисници 3 белешки

talksonweb на gmail точка com
12 години пред
The exception code can be used to categorize your errors. If you're wondering what the exception code can be used for, read on below. 

Let's say each time your application isn't able to connect to the database, you can save the error message under the error/exception code 214. At the end of the month, you can do a quick search on the error number '214' and find out how many times this error occurred. This makes life easier. Also, the error/exception message will give you details into what happened. 

The point is to use both the exception message and code. It's helpful in the long run.

Note: I added this note, because I was confused earlier as to the purpose of the exception code and it's use.
рики на рокер точка ком
пред 13 години
when raising an Exception with no error code explicitly defined, getCode() returns the integer 0 

<?php
try {
  throw new Exception("no code!!");
} catch (Exception $e) {
  print("Code='" . $e->getCode() . "'");
}
?>

outputs 

Code='0'
2M
пред 4 години
Do not use the strict operator as suggested when checking the Exception Code in \PDOException.
As per documentation: \PDOException is returning a string for its Exception Code and not an Integer.

Ran into the following in PHP8:
<?php

catch(\PDOException $e) {
    var_dump($e->getCode()); //Output: string(5) "23000"
}

?>
На оваа страница

Автоматски outline од активната документација.

Насловите ќе се појават тука по вчитување.

Попрегледно читање

Примерите, changelog табелите и user notes се визуелно издвоени за да не се губат во долгата содржина.

Брз совет Користи го outline-от Скокни директно на главните секции од активната страница.
Извор Оригиналниот линк останува достапен Кога ти треба целосен upstream context, отвори го PHP.net во нов tab.