Should Exception handling be declarative like in JSP?

Nick Sabalausky a at a.a
Mon May 23 13:41:21 PDT 2011


"Matthew Ong" <ongbp at yahoo.com> wrote in message 
news:irdf6d$2h3$1 at digitalmars.com...
> Hi D Developer,
>
> Should Exception be allow to be handled in a declarative manner?
> Basically, from what I see is the ability to allow any module/class level 
> to re-route the exception to a central handler class or function.
>
> Maybe using and introducing such new syntax, with new keyword, eg: 
> onError:
>
> void myFunctionA(...) onError(MyHandler){
>     // all exception are routed over to MyHandler
> }
>
> void myFunctionB(...) onError(AccountExHandler, AccountException){
> }
>
> class MyClassA : MyInterface, MyBase; onError(MyHandler){
>   // all exception are routed over to MyHandler
> }
>
> class MyClassB : MyInterface, MyBase; onError(AccountExHandler, 
> AccountException){
>   // only AccountException is routed over to MyHandler.
>   // all other exceptions are handled within
> }
>
> // Only a single instance would be created to handle
> // All the exceptions thrown is arranged within a queue and processed 
> serially.
> class MyHandler : mixin ExceptionHandler{ // ??? perhaps mixin interface
>    public void onException(Exception ex){
>       // ....
>    }
> }
>
> class AccountExHandler : ExceptionHandler(AccountException) {
>    public void onException(AccountException ex){ // but T is from subclass 
> of Exception
>       // Only AccountException and its sub-class/child-class will be 
> handled within here.
>    }
> }
>
>
> Please see the JSP URL. Such logic are being used in a web site manner.
> http://www.tutorialspoint.com/jsp/jsp_exception_handling.htm
> <%@ page errorPage="ShowError.jsp" %> // NOTE this line.
>
>
> Since internally each JSP file is compiled into a single class.
> This manner different JSP file can share the same Exception Handler.
> And
> Different JSP file can also have different Exception Handler.
> However, not sure if they have:
> Different Exception type can also have different Exception Handler.
>
> What do you think??
>

If you have common error handling code to be used in more than one place, 
you can just put it in a function and call the function inside a catch block 
or a scope(failure) block. Accomplishes the same thing and doesn't require 
any special features to be created.





More information about the Digitalmars-d mailing list