I'm using an official Perl driver for working with mongodb. To catch and handle errors, Try::Tiny and Safe::Isa modules are recommended. However, it doesn't work as expected. Please check code below that should work according to documentation but in fact it doesn't work:
use MongoDB;
use Try::Tiny;
use Safe::Isa;
my $client;
try {
$client = MongoDB->connect('mongodb://localhost');
$client->connect;
} catch {
warn "caught error: $_";
};
my $collection = $client->ns('foo.bar');
try {
my $all = $collection->find;
} catch {
warn "2 - caught error: $_";;
};
As far as connections are established automatically according documentation there will be no exception on connect(). But there is no exception on request too! Also I added $client->connect string to force connection, but again no exception. I'm running this script at machine where there is no mongodb installed and no mongodb docker container running so an exception definitely must appear.
Could someone explain what am I doing wrong?