【问题标题】:Catching messages thrown by classes in a lower level捕获较低级别的类抛出的消息
【发布时间】:2018-04-19 01:58:41
【问题描述】:

我的应用程序有四个级别:(1)我的应用程序,(2)pivot4j,(3)olap4j,和(4)蒙德里安

如果我在 Scala 中运行此代码:

try {
     renderer.render(model, new HtmlRenderCallback(sw)) 
}
catch {
  case ex: Exception => println(ex.getMessage)
}

应用打印出pivot4j抛出的错误:

org.olap4j.OlapException: mondrian gave exception while parsing query

如果我没有发现错误,堆栈跟踪是(相关消息以粗体显示):

play.api.http.HttpErrorHandlerExceptions$$anon$1:执行 异常[[PivotException:org.olap4j.OlapException:蒙德里安给 解析查询时出现异常]] 在 play.api.http.HttpErrorHandlerExceptions$.throwableToUsefulException(HttpErrorHandler.scala:293) 在 play.api.http.DefaultHttpErrorHandler.onServerError(HttpErrorHandler.scala:220) 在 play.api.GlobalSettings$class.onError(GlobalSettings.scala:160) 在 play.api.DefaultGlobal$.onError(GlobalSettings.scala:188) 在 play.api.http.GlobalSettingsHttpErrorHandler.onServerError(HttpErrorHandler.scala:100) 在 play.core.server.netty.PlayRequestHandler$$anonfun$2$$anonfun$apply$1.applyOrElse(PlayRequestHandler.scala:100) 在 play.core.server.netty.PlayRequestHandler$$anonfun$2$$anonfun$apply$1.applyOrElse(PlayRequestHandler.scala:99) 在 scala.concurrent.Future$$anonfun$recoverWith$1.apply(Future.scala:346) 在 scala.concurrent.Future$$anonfun$recoverWith$1.apply(Future.scala:345) 在 scala.concurrent.impl.CallbackRunnable.run(Promise.scala:36) 导致 作者:org.pivot4j.PivotException:org.olap4j.OlapException:蒙德里安 解析查询时出现异常 在 org.pivot4j.impl.PivotModelImpl.getCellSet(PivotModelImpl.java:598) 在 org.pivot4j.ui.table.TableRenderer.render(TableRenderer.java:425) 在 olap.process.RunOlap.doRunMdx(RunOlap.scala:91) 在 olap.process.RunOlap$$anonfun$runMdx$1.apply(RunOlap.scala:53) 在 olap.process.RunOlap$$anonfun$runMdx$1.apply(RunOlap.scala:51) 在 login.Authentication$LoggedAction$$anonfun$invokeBlock$1.apply(LoggedAction.scala:47) 在 login.Authentication$LoggedAction$$anonfun$invokeBlock$1.apply(LoggedAction.scala:42) 在 scala.concurrent.Future$$anonfun$flatMap$1.apply(Future.scala:253) 在 scala.concurrent.Future$$anonfun$flatMap$1.apply(Future.scala:251) 在 scala.concurrent.impl.CallbackRunnable.run(Promise.scala:36) 导致 by: org.olap4j.OlapException: mondrian 解析时出现异常 查询 在 mondrian.olap4j.MondrianOlap4jConnection$Helper.createException(MondrianOlap4jConnection.java:858) 在 mondrian.olap4j.MondrianOlap4jStatement.parseQuery(MondrianOlap4jStatement.java:375) 在 mondrian.olap4j.MondrianOlap4jStatement.executeOlapQuery(MondrianOlap4jStatement.java:346) 在 org.pivot4j.impl.PivotModelImpl.executeMdx(PivotModelImpl.java:646) 在 org.pivot4j.impl.PivotModelImpl.getCellSet(PivotModelImpl.java:596) 在 org.pivot4j.ui.table.TableRenderer.render(TableRenderer.java:425) 在 olap.process.RunOlap.doRunMdx(RunOlap.scala:91) 在 olap.process.RunOlap$$anonfun$runMdx$1.apply(RunOlap.scala:53) 在 olap.process.RunOlap$$anonfun$runMdx$1.apply(RunOlap.scala:51) 在 login.Authentication$LoggedAction$$anonfun$invokeBlock$1.apply(LoggedAction.scala:47)

原因:mondrian.olap.MondrianException: Mondrian Error: MDX object '[Measures].[Unit Cost]' not found in cube 'Sales'

蒙德里安是引发错误的人,我需要得到抛出的消息:

 MDX object '[Measures].[Unit Cost]' not found in cube 'Sales'

我试过了:

try {
     renderer.render(model, new HtmlRenderCallback(sw)) 
}
catch {
  case ex: MondrianException => println(ex.getMessage)
}

但没有发现错误。

【问题讨论】:

  • 你可以做类似try { ... } catch { case ex:OlapException => println(ex.getCause) }
  • 和 AFAIK,没有优雅的方法来捕捉 JVM 中的嵌套异常:stackoverflow.com/questions/2955458/…

标签: scala


【解决方案1】:

使用 Apache Commons ExceptionUtils 获取根异常。

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2012-07-25
    • 2016-04-28
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多