I have a Sinatra app utilizing Sequel and Postgres… it’s a very simple module that inserts into a database. I want to capture any errors from the insert and return a useful message.
My codes is as follows:
begin
sql = DB["INSERT INTO table (id, firstname, lastname, ...) values (......)"]
ds.insert
rescue Sequel::Error
...
end
How do I capture what the actual error is? I can put “There was an error” and that is printed, but I want something more specific – like “First name is required”, “Last name is required”.
Can someone help?
You can use the last exception object magic constant
$!:Also you can change the rescue block to put the exception object into a variable:
Both would print the exception messsage.