Support the ongoing development of Laravel.io →
posted 10 years ago
Packages

I am using phpseclib and if there is no connection to the server a "user_error" is thrown.

The code to simulate the problem in a Artisan Command - just use an nonexistig IP and you can simulate the problem:

public function fire()
{	
	try {
		$sshCon=SSH::into('myServer')->getGateway()->getConnection();
	} catch(RuntimeException $e) {
		$this->error($e->getMessage());
		Log::error($e);
	}
}

The Error Msg:

Cannot connect to XXX.XXX.XX.XX:22. Error 51. Network is unreachable
PHP Fatal error:  Uncaught exception 'ErrorException' with message 'Connection closed prematurely' in /SVN-Checkouts/project/vendor/phpseclib/phpseclib/phpseclib/Net/SSH2.php:3126

How can I catch this error?

I have tired to add this to /app/start/artisan.php:

App::error(function(ErrorException $exception) {
    Log::error($exception);
});

App::fatal(function($exception)
{
    Log::error($exception);
});

When I debug the app - the user_error is converted into an ErrorException which is thrown by the app but non of my custom error Handler gets called.

Last updated 3 years ago.
0

Sign in to participate in this thread!

Eventy

Your banner here too?

Moderators

We'd like to thank these amazing companies for supporting us

Your logo here?

Laravel.io

The Laravel portal for problem solving, knowledge sharing and community building.

© 2025 Laravel.io - All rights reserved.