Should Exception handling be declarative like in JSP?

Matthew Ong ongbp at yahoo.com
Mon May 23 04:03:40 PDT 2011


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??

-- 
Matthew Ong
email: ongbp at yahoo.com



More information about the Digitalmars-d mailing list