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 trialliamthornback2
9,618 Points"Unhandled exception: com.teamtreehouse.courses.exc.DaoException"
My IDE is giving me warning signals telling me the addCourse method on the sql2oCourseDao class isn't properly handling the Sql2oException.
But I'm sure my code looks the same as yours.
Here is what my sql2oCourseDao.java file lookes like:
package com.teamtreehouse.courses.dao;
import com.teamtreehouse.courses.exc.DaoException;
import com.teamtreehouse.courses.model.Course;
import org.sql2o.Connection;
import org.sql2o.Sql2o;
import org.sql2o.Sql2oException;
import java.util.List;
public class sql2oCourseDao implements CourseDao {
private List<Course> courses;
private final Sql2o sql2o;
public sql2oCourseDao(Sql2o sql2o) {
this.sql2o = sql2o;
}
@Override
public void addCourse(Course course) {
String sql = "INSERT INTO courses(name, url) VALUES (:name, :url)";
try (Connection con = sql2o.open()) {
int id = (int) con.createQuery(sql)
.bind(course)
.executeUpdate()
.getKey();
course.setId(id);
} catch (Sql2oException exc) {
throw new DaoException(exc, "Problem adding course");
}
}
@Override
public List<Course> findAll() {
return this.courses;
}
}
And here is what my DaoException.java file looks like:
package com.teamtreehouse.courses.exc;
public class DaoException extends Exception {
private final Exception originalException;
public DaoException(Exception originalException, String msg) {
super(msg);
this.originalException = originalException;
}
}
UPDATE:
I forgot to add "throws DaoException" in my addCourse method declaration. My IDE isn't giving me any trouble now.