I am using the official Perl driver to work with mongodb. To catch and handle errors, Try::Tinyand Safe::Isamodules are recommended . However, it does not work properly. Please check the code below, which should work in accordance with the documentation, but actually it does not 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: $_";;
};
, connect() . ! , $client->connect force, . script , mongodb, - mongodb, .
- , ?