Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

I can't catch exception #2

Open
zstergios opened this issue May 22, 2024 · 5 comments
Open

I can't catch exception #2

zstergios opened this issue May 22, 2024 · 5 comments

Comments

@zstergios
Copy link

Can you help?

( ! ) Fatal error: Uncaught InitPHP\Socket\Exception\SocketConnectionException: Socket Connection Error : 10060 vendor\initphp\socket\src\Client\TCP.php on line 55

        use \InitPHP\Socket\Socket;
        use \InitPHP\Socket\Exception\SocketConnectionException;
        use \InitPHP\Socket\Exception\SocketInvalidArgumentException;

	try
	{
		//error_reporting(0);
		@ini_set("default_socket_timeout",15);
		$this->client = Socket::client(Socket::TCP,$this->params['connectip'],$this->params['port']);
	}
	catch(Exception | Throwable | \SocketInvalidArgumentException | \SocketConnectionException $e)
	{
		$this->error=$e->getMessage();
		$this->setLog('connect error',$this->error);
		return false;
	}
@muhammetsafak
Copy link
Member

This means it cannot connect to the socket. I will check it at a suitable time and update if there is an error.

@zstergios
Copy link
Author

Yes I know, want to handle such errors, but can't catch the exception.

@muhammetsafak
Copy link
Member

muhammetsafak commented May 24, 2024

I understand, you are complaining about not being able to catch the error. The first error I see in your code is the "\" symbol you use at the beginning of the SocketConnectionException and SocketInvalidArgumentException errors. Try updating your code as below.

        use \InitPHP\Socket\Socket;
        use \InitPHP\Socket\Exception\SocketConnectionException;
        use \InitPHP\Socket\Exception\SocketInvalidArgumentException;
        use \Exception;
        use \Throwable;

	try
	{
		//error_reporting(0);
		@ini_set("default_socket_timeout",15);
		$this->client = Socket::client(Socket::TCP,$this->params['connectip'],$this->params['port']);
	}
	catch(Exception | Throwable | SocketInvalidArgumentException | SocketConnectionException $e)
	{
		$this->error=$e->getMessage();
		$this->setLog('connect error',$this->error);
		return false;
	}

@zstergios
Copy link
Author

I have already tried it with and without. Can you please make your own tests?
My PHP is 7.4

@zstergios
Copy link
Author

Final it's ok

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants