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've moved the forum!

Please use forum.silverstripe.org for any new questions (announcement).
The forum archive will stick around, but will be read only.

You can also use our Slack channel or StackOverflow to ask for help.
Check out our community overview for more options to contribute.

Data Model Questions /

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

Unique key and exception hanhling


Go to End


3 Posts   1221 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.