Method annotated by @Catch can't get an instance of thrown exception
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(
}
}
def index2() = {
try{
throw new Exception("2"); // An exception is thrown when doing something
}catch{
case ex: Exception => play.error(
}
}
.....
}
Why not write it like this:
trait ExceptionHandler{
this: ScalaController =>
@Catch(
def handle(ex: Exception ) : Unit ={
play.
renderText(
}
}
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
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 |