postgreSQL - What to do with Exceptions

Asgorath

[H]ard|Gawd
Joined
Jul 12, 2004
Messages
1,253
Ok, so as I'm writing my functions in plpgsql, I should be using exceptions.

DEBUG
NOTICE
EXCEPTION

I'm writing my functions to be called by a person writing in C#.

Let's say I have a function: sql_modify_user(user_id,first_name)

He calls it, but the user_id doesn't exist in the database. As the SQL programmer, I want him to know that his update didn't actually get stored in any user row. If he was running the SQL by hand, I could raise a notice. But I want his program to trap for this. How does he trap for this, and what does he do with it?

Before thinking about using exception handling, I was going to use different return values...but that's bad practice.

Would you guys lead me on a good path here?

Thanks.
 
Why are different return values bad practice?
I just return the amount of rows updated.


That's not a bad thing. But I'm sure there are many reasons for 0 rows to be updated. And those are the exceptions I'd like to bring to the attention to the program calling on my database.
 
Presumably the other programmer can read the manual and learn how to either catch or query for exceptions as needed by the specific API he's using.

Just saying he's writing his code in C# doesn't actually tell us anything about what DB API he's using. Unless he's linking with libpq, more than likely the API will throw native C# exceptions of some suitable class.
 
Back
Top