improve exception handling
This commit is contained in:
@@ -2,6 +2,7 @@ package com.minres.tgc.hammer
|
|||||||
|
|
||||||
import ch.qos.logback.classic.Level
|
import ch.qos.logback.classic.Level
|
||||||
import com.minres.tgc.hammer.cli.{HammerConf, MySubcommand}
|
import com.minres.tgc.hammer.cli.{HammerConf, MySubcommand}
|
||||||
|
import com.minres.tgc.hammer.util.AssertException
|
||||||
import com.typesafe.scalalogging.Logger
|
import com.typesafe.scalalogging.Logger
|
||||||
import org.slf4j.LoggerFactory
|
import org.slf4j.LoggerFactory
|
||||||
|
|
||||||
@@ -36,8 +37,11 @@ object Main {
|
|||||||
try {
|
try {
|
||||||
tasks.foreach(_.run())
|
tasks.foreach(_.run())
|
||||||
} catch {
|
} catch {
|
||||||
case e: Exception =>
|
case e: AssertException =>
|
||||||
logger.error(s"Error during task execution, see above!")
|
logger.error(s"Error during task execution, see above!")
|
||||||
|
case e: Exception =>
|
||||||
|
logger.error(s"General exception ${e.getMessage}")
|
||||||
|
e.printStackTrace()
|
||||||
}
|
}
|
||||||
case _ =>
|
case _ =>
|
||||||
logger.error(s"Found no subcommand, see help below")
|
logger.error(s"Found no subcommand, see help below")
|
||||||
|
@@ -0,0 +1,3 @@
|
|||||||
|
package com.minres.tgc.hammer.util
|
||||||
|
|
||||||
|
case class AssertException() extends Exception
|
@@ -10,7 +10,7 @@ trait Logging[T: ClassTag] {
|
|||||||
protected def assert(boolean: Boolean, msg: String): Unit = {
|
protected def assert(boolean: Boolean, msg: String): Unit = {
|
||||||
if (!boolean) {
|
if (!boolean) {
|
||||||
log.error(msg)
|
log.error(msg)
|
||||||
throw new Exception()
|
throw AssertException()
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Reference in New Issue
Block a user