Skip to content

Commit bb17999

Browse files
committed
improve throw/catch frequency
1 parent f561962 commit bb17999

File tree

1 file changed

+33
-2
lines changed

1 file changed

+33
-2
lines changed

examples/write.php

Lines changed: 33 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,16 @@
2424
"nick" => "Bobby Fischer",
2525
"citizen" => "USA",
2626
);
27+
$kasparov = array(
28+
"name" => "Garry Kimovich Kasparov",
29+
"nick" => "Kasparov",
30+
"citizen" => "Russia",
31+
);
32+
$spassky = array(
33+
"name" => "Boris Vasilievich Spassky",
34+
"nick" => "Spassky",
35+
"citizen" => "France",
36+
);
2737

2838
try {
2939
$result = $collection->insertOne($hannes);
@@ -48,7 +58,7 @@
4858
var_dump($document);
4959
}
5060
} catch(Exception $e) {
51-
echo $e->getMessage(), "\n";
61+
printf("Caught exception '%s', on line %d\n", $e->getMessage(), __LINE__);
5262
exit;
5363
}
5464

@@ -69,6 +79,13 @@
6979
var_dump($person);
7080
}
7181

82+
} catch(Exception $e) {
83+
printf("Caught exception '%s', on line %d\n", $e->getMessage(), __LINE__);
84+
exit;
85+
}
86+
87+
88+
try {
7289
$result = $collection->updateMany(
7390
array("citizen" => "Iceland"),
7491
array('$set' => array("viking" => true))
@@ -79,6 +96,14 @@
7996
foreach($result as $document) {
8097
var_dump($document);
8198
}
99+
} catch(Exception $e) {
100+
printf("Caught exception '%s', on line %d\n", $e->getMessage(), __LINE__);
101+
exit;
102+
}
103+
104+
105+
try {
106+
echo "This is the trouble maker\n";
82107
$result = $collection->replaceOne(
83108
array("nick" => "Bobby Fischer"),
84109
array("name" => "Magnus Carlsen", "nick" => "unknown", "citizen" => "Norway")
@@ -88,14 +113,20 @@
88113
foreach($result as $document) {
89114
var_dump($document);
90115
}
116+
} catch(Exception $e) {
117+
printf("Caught exception '%s', on line %d\n", $e->getMessage(), __LINE__);
118+
exit;
119+
}
91120

121+
122+
try {
92123
$result = $collection->deleteOne($document);
93124
printf("Deleted: %d (out of expected 1)\n", $result->getNumRemoved());
94125

95126
$result = $collection->deleteMany(array("citizen" => "Iceland"));
96127
printf("Deleted: %d (out of expected 2)\n", $result->getNumRemoved());
97128
} catch(Exception $e) {
98-
echo $e->getMessage(), "\n";
129+
printf("Caught exception '%s', on line %d\n", $e->getMessage(), __LINE__);
99130
exit;
100131

101132
}

0 commit comments

Comments
 (0)