2.7 KiB
		
	
	
	
	
	
	
	
			
		
		
	
	
			2.7 KiB
		
	
	
	
	
	
	
	
BigDL provides error handling api. Please don't use assert, raise, throw to fail the application.
Use the error handling api instead, it will provide useful message for debugging.
Error handling API
Scala
Import package
import com.intel.analytics.bigdl.dllib.utils.Log4Error
If user's input is invalid
Log4Error.invalidInputError(condition: Boolean, errmsg: String, fixmsg: String = null)
condition: Will throw exception and print errmsg if it'sfalse. Otherwise will pass the functionerrmsg: Error message to be print.fixmsg: Message about how to fix the error.
If user call the api wrong
Log4Error.invalidOperationError(condition: Boolean, errmsg: String, fixmsg: String = null, cause: Throwable = null)
condition: Will throw exception and print errmsg if it'sfalse. Otherwise will pass the functionerrmsg: Error message to be print.fixmsg: Message about how to fix the error.cause: Exception need to throw.
For unkown Exception:
Log4Error.unKnowExceptionError(condition: Boolean, errmsg: String, fixmsg: String = null, cause: Throwable = null)
condition: Will throw exception and print errmsg if it'sfalse. Otherwise will pass the functionerrmsg: Error message to be print.fixmsg: Message about how to fix the error.cause: Exception need to throw.
Notes: This API is for future extension, in case we need distinct invalidOperation exception with unKnownException in python
Python
Import package
from bigdl.dllib.utils.log4Error import *
If user's input is invalid
invalidInputError(condition, errMsg, fixMsg=None)
condition: Will throw exception and print errmsg if it'sfalse. Otherwise will pass the functionerrMsg: Error message to be print.fixMsg: Message about how to fix the error.
If user call the api wrong
invalidOperationError(condition, errMsg, fixMsg=None, cause=None)
condition: Will throw exception and print errmsg if it'sfalse. Otherwise will pass the functionerrMsg: Error message to be print.fixMsg: Message about how to fix the error.cause: Exception need to throw.
Examples
Scala
If you want to use:
assert(a > 0)
or
require(a > 0)
or
if (a <= 0) {
  throw new Exception()
}
Please use below code instead
Log4Error.invalidInputError(a>0, errmsg="a is negative", fixmsg="expect a is positive")
Python
If you want to use:
assert(a > 0)
or
if (a <= 0) {
  raise Exception()
}
Please use below code instead
invalidInputError(a>0, errMsg="a is negative", fixMsg="expect a is positive")