ipex-llm/docs/readthedocs/source/doc/error-log-api.md
Yuwen Hu 0407ebf5c3 [Doc] Remove manually-added bold styles for titles (#6215)
* Remove manually-added bold style for titles in [User guide] section

* Fix failed relative links in windows user guide

* Remove manually-added bold style for titles in [Orca] section

* Fix failed relative links & title bold fix in Nano 5 min

* Remove manually-added bold style for titles in [Nano] section

* Remove manually-added bold style for titles in [DLlib] section

* Remove manually-added bold style for titles in [Chronos] section

* Remove manually-added bold style for titles in Developer guide

* Remove manually-added bold title style for all other not-included md files in docs/readthedocs/source/doc folder

* Fix based on comments
2022-10-20 13:48:22 +08:00

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's false. Otherwise will pass the function
  • errmsg: 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's false. Otherwise will pass the function
  • errmsg: 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's false. Otherwise will pass the function
  • errmsg: 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's false. Otherwise will pass the function
  • errMsg: 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's false. Otherwise will pass the function
  • errMsg: 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")