
SQLite3::exec 메서드는 SQL 명령을 실행할 때 에러를 처리하는 방법은 두 가지가 있습니다.
1. 에러 메시지를 확인하는 방법: SQLite3::exec 메서드는 에러 메시지를 반환하지 않습니다. 하지만 SQLite3::last_error 메서드를 사용하여 에러 메시지를 확인할 수 있습니다.
#hostingforum.kr
ruby
db = SQLite3::Database.new('example.db')
begin
db.execute('SELECT * FROM non_existent_table')
rescue SQLite3::SQLException => e
puts e.message
end
2. 에러를 예외로 처리하는 방법: SQLite3::exec 메서드는 예외를 발생시켜 에러를 처리할 수 있습니다. 예를 들어, SQL 문법 오류가 발생하면 SQLite3::SQLException 예외가 발생합니다.
#hostingforum.kr
ruby
db = SQLite3::Database.new('example.db')
begin
db.execute('SELECT * FROM non_existent_table')
rescue SQLite3::SQLException => e
puts e.message
end
이러한 방법을 사용하여 SQLite3::exec 메서드의 에러를 처리할 수 있습니다.
2025-05-17 14:10