Skip to main content

This site requires you to update your browser. Your browsing experience maybe affected by not having the most up to date version.

We're retiring the forums!

The SilverStripe forums have passed their heyday. They'll stick around, but will be read only. We'd encourage you to get involved in the community via the following channels instead:

Data Model Questions /

Moderators: martimiz, Sean, Ed, biapar, Willr, Ingo, swaiba

Unique key and exception hanhling


Go to End


3 Posts   998 Views

Avatar
mishell

Community Member, 19 Posts

23 August 2011 at 1:22am

I have unique index on two fields (COL1,CoL2)

I wanna write it to DB, but on failure I don't want to throw any user error. Just that one that I want to show. I made

                try {
                    $branch->write();
                }
                catch(ValidationException $e) {
                  $bad++
                  show_error_with_bad_results($bad);
                }

but It doesn't seem to catch it. I t throws user error instead. How could I make it work.

Avatar
Willr

Forum Moderator, 5523 Posts

23 August 2011 at 8:08pm

SS doesn't use exceptions very much, I think in this case you'll need to manually do your insert or detect the conflict. There is a plan to get us away from the user_error() world but that's a big task!

Avatar
mishell

Community Member, 19 Posts

23 August 2011 at 8:35pm

I thought I can make it by DO, if now well... Thank You anyway.

M.