Announcement

Collapse
No announcement yet.
X
  • Filter
  • Time
Clear All
new posts

    Server exception handling

    Hi,
    In my application, i m trying to generate a sequential and unique number for the users.

    what i m doing is to use a table to store all the existing numbers, and use SQL:

    Code:
    SELECT MAX(num) + 1 FROM table
    to get the max number, and plus one as the next sequential number for the user. When the number is generated, the number is saved into the table, hence next time the SQL will get this number as the max number.

    To avoid duplicated numbers, i added a UNIQUE constraint to the table, so the column will not accept same number to appear twice.

    But there could be a problem when concurrent requests are to be processed at the same time, because SELECT for the max number and INSERT for the max number + 1 are executed in order, two transactions can get the same max number, when plus one and save, the first transaction is able to INSERT, but the second one will encounter a "duplicated value" exception.

    I use two computer to do a test, and when the exception happens, it pops up a window with a warning message like "duplicated values are not accepted" something.

    I m wondering if there's a way that i can catch this exception at the client side, and do something to it, e.g. regenerate a number. Is the exception in the DSResponse.getData()? and how can i get it?

    Thanks!

    P.S. i can't test it under hosted mode, because the URL seems to work only locally, can't be accessed from another computer
    Last edited by ledais0802; 20 Oct 2010, 17:56.

    #2
    Sorry that the problem is solved 5 min later after i posted this thread.

    Here's what i did. I used a RPCManager exception handler to handle the server errors.

    Code:
    		RPCManager.setHandleErrorCallback(new HandleErrorCallback() {
    			public void handleError(DSResponse response, DSRequest request) {
    				SC.say("failed to save the number, redo it. Status = " + response.getStatus());
    				generateNumber();
    			}
    		});
    it shows that when a server exception is thrown back to the client, the DSResponse.getStatus() is -1, so i could capture this value, and call the method again.

    Another question. It looks to me that the RPCManager.setHandleErrorCallback is like a global setting, so my question is if i set it somewhere in the code, will all server exceptions be handled the same way, in this case calling the same method? how do i differentiate server exceptions?

    Comment

    Working...
    X