From: Markus W. <wo...@21...> - 2005-09-06 11:48:54
|
Hey guys, I'm trying to throw Javascript exceptions in JPSpan from the server side using JPSpan_Error like this: if (PEAR::isError($obj)) { $err = new JPSpan_Error($obj->getCode(), "get_record_by_criteria()", $obj->getMessage()); return $err; } This doesn't seem to work though, JPSpan just opens an alert window with the error text and that's it, no catchable exception is fired. Is there a way to throw actual exceptions from the server-side, which I can use in a try...catch block on the client-side? CU Markus |
From: Markus W. <wo...@21...> - 2005-09-07 20:51:09
|
Hi Harry, thanks for answering ;-) Okay, so it's quite straightforward when dealing with async calls, but what about synchronous ones, where I don't have a handler object for callbacks? CU Markus Harry Fuecks wrote: > OK - the reason for the alert is the default client-side error handling > mechanism - unless you override it you get an alert. > > The fundamental problem with exceptions and async calls is how to > transmit the exception to the callback function that handles the > response, given that it's not the caller. In JPSpan this is basically > done by special callback functions for errors, using a naming convention. > > The basic choice you have to "catch" your exception is either "locally" > in your handler or "globally" for all calls through a specific "remote > object" class. > > To do this "locally", create a function in your handler with the same > name as the remote method but with the string "Error" as the end of the > function name. For example, if your remote method is something like; > > math.divide(x,y) > > In your MathHandler, you would define a function called "divide" to > handle a non-error responses and a function "divideError" which will be > passed the exception object if an exception happens. This function > "divideError" will only be passed exceptions you specifically "threw" > from PHP, not other exceptions like network errors etc. > > The other option you have is to redefine some special functions in your > remote object class in Javascript. If you look the script > "remoteobject.js" in the source, the functions you need to look at are > clientErrorFunc, serverErrorFunc and applicationErrorFunc - see the > comments in the source for their purpose. You would want to redefine > applicationErrorFunc to "globally" handle all exceptions you throw from > PHP e.g.; > > var myErrorHandlingFunc = function(e) { > // do something here > } > > var m = new math(MathHandler); > m.applicationErrorFunc = myErrorHandlingFunc; > > If you look at the "examples/postoffice_client_generated.php" script, > you'll see some more examples. > > Regards, > > Harry > On 9/6/05, *Markus Wolff* <wo...@21... <mailto:wo...@21...>> wrote: > > Hey guys, > > I'm trying to throw Javascript exceptions in JPSpan from the server side > using JPSpan_Error like this: > > if (PEAR::isError($obj)) { > $err = new JPSpan_Error($obj->getCode(), > "get_record_by_criteria()", > $obj->getMessage()); > return $err; > } > > This doesn't seem to work though, JPSpan just opens an alert window with > the error text and that's it, no catchable exception is fired. > > Is there a way to throw actual exceptions from the server-side, which I > can use in a try...catch block on the client-side? > > CU > Markus |
From: Harry F. <hf...@gm...> - 2005-09-07 21:58:50
|
Hmmm - looking at the code again, looks like sync calls will always pass=20 exceptions to applicationErrorFunc rather than letting them bubble through.= =20 In retrospect that seems like a mistake but I've bias against sync calls ( http://ajaxblog.com/archives/2005/05/25/synchronous-requests-bad) so that= =20 code is old. You'd basically have to redefine applicationErrorFunc to=20 re-throw the exception in Javascript, then you'd get it coming back at you. On 9/7/05, Markus Wolff <wo...@21...> wrote: >=20 > Hi Harry, >=20 > thanks for answering ;-) >=20 > Okay, so it's quite straightforward when dealing with async calls, but > what about synchronous ones, where I don't have a handler object for > callbacks? >=20 > CU > Markus >=20 > Harry Fuecks wrote: > > OK - the reason for the alert is the default client-side error handling > > mechanism - unless you override it you get an alert. > > > > The fundamental problem with exceptions and async calls is how to > > transmit the exception to the callback function that handles the > > response, given that it's not the caller. In JPSpan this is basically > > done by special callback functions for errors, using a naming=20 > convention. > > > > The basic choice you have to "catch" your exception is either "locally" > > in your handler or "globally" for all calls through a specific "remote > > object" class. > > > > To do this "locally", create a function in your handler with the same > > name as the remote method but with the string "Error" as the end of the > > function name. For example, if your remote method is something like; > > > > math.divide(x,y) > > > > In your MathHandler, you would define a function called "divide" to > > handle a non-error responses and a function "divideError" which will be > > passed the exception object if an exception happens. This function > > "divideError" will only be passed exceptions you specifically "threw" > > from PHP, not other exceptions like network errors etc. > > > > The other option you have is to redefine some special functions in your > > remote object class in Javascript. If you look the script > > "remoteobject.js" in the source, the functions you need to look at are > > clientErrorFunc, serverErrorFunc and applicationErrorFunc - see the > > comments in the source for their purpose. You would want to redefine > > applicationErrorFunc to "globally" handle all exceptions you throw from > > PHP e.g.; > > > > var myErrorHandlingFunc =3D function(e) { > > // do something here > > } > > > > var m =3D new math(MathHandler); > > m.applicationErrorFunc =3D myErrorHandlingFunc; > > > > If you look at the "examples/postoffice_client_generated.php" script, > > you'll see some more examples. > > > > Regards, > > > > Harry > > On 9/6/05, *Markus Wolff* <wo...@21... <mailto:wo...@21...>> wrote: > > > > Hey guys, > > > > I'm trying to throw Javascript exceptions in JPSpan from the server sid= e > > using JPSpan_Error like this: > > > > if (PEAR::isError($obj)) { > > $err =3D new JPSpan_Error($obj->getCode(), > > "get_record_by_criteria()", > > $obj->getMessage()); > > return $err; > > } > > > > This doesn't seem to work though, JPSpan just opens an alert window wit= h > > the error text and that's it, no catchable exception is fired. > > > > Is there a way to throw actual exceptions from the server-side, which I > > can use in a try...catch block on the client-side? > > > > CU > > Markus >=20 > |
From: Harry F. <hf...@gm...> - 2005-09-07 22:24:20
|
OK - the reason for the alert is the default client-side error handling=20 mechanism - unless you override it you get an alert. The fundamental problem with exceptions and async calls is how to transmit= =20 the exception to the callback function that handles the response, given tha= t=20 it's not the caller. In JPSpan this is basically done by special callback= =20 functions for errors, using a naming convention. The basic choice you have to "catch" your exception is either "locally" in= =20 your handler or "globally" for all calls through a specific "remote object"= =20 class. To do this "locally", create a function in your handler with the same name= =20 as the remote method but with the string "Error" as the end of the function= =20 name. For example, if your remote method is something like; math.divide(x,y) In your MathHandler, you would define a function called "divide" to handle = a=20 non-error responses and a function "divideError" which will be passed the= =20 exception object if an exception happens. This function "divideError" will= =20 only be passed exceptions you specifically "threw" from PHP, not other=20 exceptions like network errors etc. The other option you have is to redefine some special functions in your=20 remote object class in Javascript. If you look the script "remoteobject.js"= =20 in the source, the functions you need to look at are clientErrorFunc,=20 serverErrorFunc and applicationErrorFunc - see the comments in the source= =20 for their purpose. You would want to redefine applicationErrorFunc to=20 "globally" handle all exceptions you throw from PHP e.g.; var myErrorHandlingFunc =3D function(e) { // do something here } var m =3D new math(MathHandler); m.applicationErrorFunc =3D myErrorHandlingFunc; If you look at the "examples/postoffice_client_generated.php" script, you'l= l=20 see some more examples. Regards, Harry On 9/6/05, Markus Wolff <wo...@21...> wrote: >=20 > Hey guys, >=20 > I'm trying to throw Javascript exceptions in JPSpan from the server side > using JPSpan_Error like this: >=20 > if (PEAR::isError($obj)) { > $err =3D new JPSpan_Error($obj->getCode(), "get_record_by_criteria()", > $obj->getMessage()); > return $err; > } >=20 > This doesn't seem to work though, JPSpan just opens an alert window with > the error text and that's it, no catchable exception is fired. >=20 > Is there a way to throw actual exceptions from the server-side, which I > can use in a try...catch block on the client-side? >=20 > CU > Markus >=20 >=20 > ------------------------------------------------------- > SF.Net email is Sponsored by the Better Software Conference & EXPO > September 19-22, 2005 * San Francisco, CA * Development Lifecycle=20 > Practices > Agile & Plan-Driven Development * Managing Projects & Teams * Testing & Q= A > Security * Process Improvement & Measurement * http://www.sqe.com/bsce5sf > _______________________________________________ > Jpspan-discuss mailing list > Jps...@li... > https://lists.sourceforge.net/lists/listinfo/jpspan-discuss > |