Method annotated by @Catch can't get an instance of thrown exception

Bug #591815 reported by Archer
8
This bug affects 1 person
Affects Status Importance Assigned to Milestone
play framework
Fix Committed
Undecided
Unassigned
1.1
Fix Committed
Undecided
Unassigned

Bug Description

et's say we have defined lots of Controllers(I called these as REST api) , now I want to log the exception when it occurs, but it is tedious to surround try { .. } catch { .. } in
every controller method , like this:

object Application extends ScalaController{
def index1() = {
   try{
     throw new Exception("1"); // An exception is thrown when doing something
   }catch{
      case ex: Exception => play.error(ex.getMessage) ; renderText(ex.getMessage)
   }
}
def index2() = {

   try{
     throw new Exception("2"); // An exception is thrown when doing something
   }catch{
      case ex: Exception => play.error(ex.getMessage) ; renderText(ex.getMessage)
   }
}

.....
}

Why not write it like this:

trait ExceptionHandler{

this: ScalaController =>
@Catch(Array(classOf[Exception]))
def handle(ex: Exception ) : Unit ={
    play.error(ex.getMessage) //Log all of the exception message here !!
    renderText(ex.getMessage) // And return it to the client
}
}

object Application extends ScalaController with ExceptionHandler{
def index1() {
  throw new Exception('1") // No need to surround `try { .. } catch{ .. } ` any more
}

def index2(){
    throw new Exception("2") // No need to surround `try { .. } catch{ .. } ` any more
}
 .....
}

However, the method handle in ExceptionHandler can't get the instance of thrown exception. This issue is related with not only Scala but Java. I don't know what's wrong .

Please give me a clear suggestion or solution

BTW, Writing an exception handler plugin can log the exception message but can't return it to the client

This idea is similar to AOP's. But I found that Spring AOP can't be used here

Archer (ggd543)
security vulnerability: yes → no
visibility: private → public
Changed in play:
milestone: none → 1.1
milestone: 1.1 → none
Changed in play:
status: New → Fix Committed
To post a comment you must log in.
This report contains Public information  
Everyone can see this information.

Other bug subscribers

Remote bug watches

Bug watches keep track of this bug in other bug trackers.