A
A
Anastasia2021-06-28 21:54:29
PHP
Anastasia, 2021-06-28 21:54:29

How to get errors with php if you are not working through a browser?

Hello. I'm making myself a telegram bot in PHP and faced such an inconvenient situation - I don't see an error. This is due to the fact that I work not through a browser, but through Telegram. And if there is an error in the code, the script just stops. In order to somehow debug the code, I have to simulate (yeah). Simulate a request from a cart, substitute it into variables and open the page from the browser. Firstly, it's inconvenient, and secondly, I often see an error from the cart, saying "the request that you send me is already outdated" (this applies to inline buttons, because they have a lifetime)

Sending messages to the cart occurs through this function :

tlgrm('sendMessage', ['text' => 'Само сообщение']);


Is there any way to make it so that in case of an error, it is sent to me in telegram? like ['text' => $error]

ps there are logs, but this is also inconvenient

Answer the question

In order to leave comments, you need to log in

1 answer(s)
B
Barmunk, 2021-06-28
@Barmunk

try {
   tlgrm('sendMessage', ['text' => 'Само сообщение']);
} catch (Throwable $t) {
    tlgrm('sendMessage', ['text' => $t->getMessage()]);
}

try {
    // Code that may throw an Exception or Error.
} catch (Throwable $t) {
    // Executed only in PHP 7, will not match in PHP 5.x
} catch (Exception $e) {
    // Executed only in PHP 5.x, will not be reached in PHP 7
}

https://habr.com/ru/post/261451/

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question