Welcome to the Treehouse Community
Want to collaborate on code errors? Have bugs you need feedback on? Looking for an extra set of eyes on your latest project? Get support with fellow developers, designers, and programmers of all backgrounds and skill levels here with the Treehouse Community! While you're at it, check out some resources Treehouse students have shared here.
Looking to learn something new?
Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and join thousands of Treehouse students and alumni in the community today.
Start your free trialRobert Valencia
Courses Plus Student 3,735 PointsWhat am I missing? The error I’m getting is that there is no Exception class
I’ve watched the video, checked my Workspace, researched online for other examples and read through the documentation, and I still can’t figure out what I’m doing wrong.
<?php
//Place your code below this comment
try{
$db = new PDO('sqlite::memory');
$db->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION);
} catch(Exception $e) {
echo $e->getMessage;
}
?>
2 Answers
Remylus Losius
7,394 PointsBoth of your Exception answers are good, but I guess the quiz expects a simpler response. This works for me:
try {
// your code;
} catch(Exception $e) {
echo "error";
}
Team Treehouse, "There is no Exception class" is not helpful.
Samuel Zhen
33,571 Points<?php
try{
$db = new PDO('sqlite::memory');
$db->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION);
} catch(PDOException $e) {
echo $e->getMessage;
}
It should be PDOException
Robert Valencia
Courses Plus Student 3,735 PointsThanks, I had tried this too, and it should’ve taken it in my opinion. But as Remylus mentioned, the quiz expected a simpler answer.
Robert Valencia
Courses Plus Student 3,735 PointsRobert Valencia
Courses Plus Student 3,735 PointsThank you, I believe my answer ended up being like this. :) I appreciate your help!