Hi,
This approach does not help resolve the real need.
Many databases implement a command or function like RAISE to throw a
custom (business) exception that is injected in normal database error
handling.

In the same way that RULES, TRIGGERS and other constraint types  are
used to impose business integrity rules to database tables and operations,
RAISE is the correct vehicle to express that business exceptional
condition for GUI, Logging or what ever needed and to handle it properly.

For example in IBM DB2 , this is implemented as a function: 

        RAISE_ERROR(/ sqlstate/,/ diagnostic-string/)

I thinks this is a very clean a useful implementation because it can be user 
even in querys.

http://publib.boulder.ibm.com/infocenter/dzichelp/v2r2/topic/com.ibm.db2.doc.sqlref/fraisee.htm#fraisee
 

> The RAISE_ERROR function causes the statement that invokes the
> function to return an error with the specified SQLSTATE (along with
> SQLCODE -438) and error condition. The RAISE_ERROR function always
> returns NULL with an undefined data type.
>
> sqlstate
>     An expression that returns a character string (CHAR or VARCHAR) of
>     exactly 5 characters. The sqlstate value must follow these rules
>     for application-defined SQLSTATEs:
>
>         * Each character must be from the set of digits ('0' through
>           '9') or non-accented upper case letters ('A' through 'Z').
>         * The SQLSTATE class (first two characters) cannot be '00',
>           '01', or '02' because these are not error classes.
>         * If the SQLSTATE class (first two characters) starts with the
>           character '0' through '6' or 'A' through 'H', the subclass
>           (last three characters) must start with a letter in the
>           range 'I' through 'Z'.
>         * If the SQLSTATE class (first two characters) starts with the
>           character '7', '8', '9', or 'I' though 'Z', the subclass
>           (last three characters) can be any of '0' through '9' or 'A
>           through 'Z'.
>
> diagnostic-string
>     An expression that returns a character string with a data type of
>     CHAR or VARCHAR and a length of up to 70 bytes. The string
>     contains EBCDIC data that describes the error condition. If the
>     string is longer than 70 bytes, it is truncated. 
>
> To use this function in a context where Rules for result data types
> <http://publib.boulder.ibm.com/infocenter/dzichelp/v2r2/topic/com.ibm.db2.doc.sqlref/rc2lerd.htm#rc2lerd>
> do not apply, such as alone in a select list, you must use a cast
> specification to give a data type to the null value that is returned.
> The RAISE_ERROR function is most useful with CASE expressions.
>
> //

I hope this help.
regards,
Dario



El 28/01/10 07:29, lvr123 escribió:
> You have to catch the error at GUI level and make it more user-
> friendly, by using the sql error codes.
> This way you could handle Internalization fore example.
>
>   

> On Jan 27, 9:56 pm, jomarlla <[email protected]> wrote:
>   
>> Thanx for the answer Thomas, but I have already used Exceptions in H2
>> and as you said It worked.
>> The problem is: if I use just exceptions with one of my java
>> functions:
>>
>> For example:
>> select st_Geomfromtext ('POINTT (10 20)');
>>
>> This function throws an exception with this messages: "Unknown
>> geometry type: POINTT"
>>
>> The problem is that for the user is really difficult to find the
>> message "Unknown geometry type: POINTT" among all the exception
>> messages, as you can see in the code below. Thats because H2 writes
>> his exception messages before mine. I though about sending a message
>> to the user without using exceptions (as postgres can do with raise
>> notice). If there is any other way I can write my exception message at
>> the top of the messages please let me know.
>>
>> Thanx a lot,
>> Jose
>>
>>     
>>
>>> H2 supports only Java procedures and functions. In Java, you could use:
>>>       
>>> throw new SQLException("no connection");
>>>       
>>> Regards,
>>> Thomas
>>>       
>>> On Tue, Jan 26, 2010 at 3:32 PM, jomarlla <[email protected]> wrote:
>>>       
>>>> Hi everyone,
>>>> This is my first post in this list and first of all I want to express
>>>> my gratitude about this fantastic project.  I want to say Hi to all
>>>> the people in this list too.
>>>>         
>>>> I do not know how to send a message to the client from a java store
>>>> procedure, for example: in PostgreSQL (in plpgsql) I can use RAISE
>>>> NOTICE 'message'. Does H2 have something similar?. I want to send this
>>>> message from a java store procedure that does not have a reference to
>>>> the object connection.
>>>>         

-- 
You received this message because you are subscribed to the Google Groups "H2 
Database" group.
To post to this group, send email to [email protected].
To unsubscribe from this group, send email to 
[email protected].
For more options, visit this group at 
http://groups.google.com/group/h2-database?hl=en.

Reply via email to