www.digitalmars.com         C & C++   DMDScript  

digitalmars.D - Should Exception handling be declarative like in JSP?

reply Matthew Ong <ongbp yahoo.com> writes:
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 yahoo.com
May 23 2011
next sibling parent Bernard Helyer <b.helyer gmail.com> writes:
On Mon, 23 May 2011 19:03:40 +0800, Matthew Ong wrote:
 What do you think??

It's a poorly defined solution to an undefined problem. Have you written a significant body of D code? Have you used D to solve problems? D is not Java, D is not Java with JSP. Furthermore language/ environment X does Y this way, why doesn't D do it this way is not in anyway a good justification for a design. Come up with real world examples of why this is a good thing, and don't just point at some other place that's done the same. I don't mean to be hostile, but there are a lot of bike shedder's on this NG, and I don't want to encourage more.
May 23 2011
prev sibling parent "Nick Sabalausky" <a a.a> writes:
"Matthew Ong" <ongbp yahoo.com> wrote in message 
news:irdf6d$2h3$1 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.
May 23 2011