When I try to connect with the Redis server with this code I haven’t any problem testing if the server is UP. The problem is when the server is DOWN. In that case I solved this escenario with the classic Try/catch. My problem is that I’d like to manage this exception with “my_custom_exception” class, which has more useful functions, instead of the class Exception. Is there anyway of making this?. I know how to extend the class Exception, but in this case is a library of third parts.
function show_status_redis_server(){
try{
$redis = RedisDB::fetch_instance();//this ...........................
}catch(Exception $e){
echo "Redis server is down";
}
}
As @Mike says in his comment it depends on where you want to make use of the functionality. The easiest thing is going to be to handle it in the code using the class:
or
Beynond that i can think of two ways… make a wrapper library that use the redis lib you are using but serves as an intermidary – this way you can catch the generic exceptions in your libraries classes and then throw whatever you want.
Second way would be to just do a custom error handler that catches uncaught exceptions – inspects them for redis somehow, and then rethrows custom exceptions. However at that point you have to let the exceptions fall through until the end of execution which doesnt give you many options for handling them unless its just to format and output messages.