Inserting rows into master table from multiple threads

We have a master table, say with two columns name (varchar) and id
(number) and a stored procedure insert_name_details(name, other
details).

SP will first check if name is present in master table or not. If
present, it will get the id otherwise it will insert a row in master
table with a new sequence number and use that id in other tables as
foreign key. So its basically an atomic "get or create-if-not found"
operation.

Both these options are for stored procedure implementation although
code is written is Java style.

Which method is preferred? Locking table or catching exceptions? I
know that using exceptions should not be used to drive logical flow,
but it makes life simpler for a programmer vs. locking table. Also
locking tables means holding resources from other threads, but table
will be locked for a brief amount of time i.e. till master row is
inserted.