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 trial

PHP PHP & Databases with PDO PDO Database Security PHP & Databases with PDO

Robert Valencia
PLUS
Robert Valencia
Courses Plus Student 3,735 Points

What 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.

index.php
<?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

Both 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.

Robert Valencia
Robert Valencia
Courses Plus Student 3,735 Points

Thank you, I believe my answer ended up being like this. :) I appreciate your help!

<?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
Robert Valencia
Courses Plus Student 3,735 Points

Thanks, I had tried this too, and it should’ve taken it in my opinion. But as Remylus mentioned, the quiz expected a simpler answer.