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

PDO Exception - Code Challenge

What is wrong with me that I can't see this?! Somebody help~

The Code Challenge says "Wrap our $db object in a try catch block. Then set up the catch statement to look for any Exception class and pass it to an object named $e"

But I keep getting an error message "Bummer! It looks like there is no Exception class"

<?php
//Place your code below this comment
try {
  $db = new PDO('sqlite::memory');
} catch ( Exception $e ) {
  echo $e->getMessage();
  die();
}
?>

And all I had to do to pass the code challenge was remove the lines inside the catch. Sometimes these challenges are so random...

Sean T. Unwin
Sean T. Unwin
28,690 Points

Hi Eric,

Glad you worked it out and I can understand your feeling about some of the challenges. In this case don't do more than was asked. ;-)

I have formatted your post so that the code display correctly.

Please post your comment as an answer and then select it as best answer, plus you'll get the points for it. :)

3 Answers

Sean T. Unwin
Sean T. Unwin
28,690 Points

Hi Kim Schmidt,

The answer is just like Eric has in his post, EXCEPT for the statements within the catch block. You only to create the catch, but don't put anything in it.

<?php
//Place your code below this comment
try {
  $db = new PDO('sqlite::memory');
} catch ( Exception $e ) { }
?>
Kim Schmidt
Kim Schmidt
2,562 Points

I'm experiencing the same problem "Bummer! It looks like there is no Exception class".

I'm 100% sure that I typed it in correctly. Could somebody please look into this?

Thank you.

Kim Schmidt
Kim Schmidt
2,562 Points

Hey Sean

Sorry missed the "remove the lines" part. Thank you for the quick reply.