exception

package
v0.17.3 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Jul 25, 2025 License: MIT Imports: 5 Imported by: 16

README

What are the functions?

  • exception
    • func
      • ThrowRefuseException (抛出RefuseException异常)
      • ThrowRefuseExceptionf (抛出RefuseException异常)
      • ThrowException (抛出Exception异常)
      • ThrowExceptionf (抛出Exception异常)
      • Try(执行有可能发生异常的代码块)
        • CatchRefuseException(捕获RefuseException异常)
        • CatchStringException(捕获String异常)
        • CatchException(捕获任意类型的异常)
        • ThrowUnCatch(异常没有捕获到时,向上层抛出异常)

Getting Started

try := exception.Try(func() {
    panic("panic throw")
})
try.CatchRefuseException(func(exp *exception.RefuseException) {
    flog.Warning(exp.Message)   // Type does not match, will not run
})
try.CatchStringException(func(exp string) {
    flog.Info(exp)  // this will run
})
try.CatchException(func(exp any) {
    flog.Error(exp) // StringException is match, will not run
})

// print: [Info] panic throw
try := exception.Try(func() {
    exception.ThrowRefuseException("test is throw")
})
try.CatchStringException(func(exp string) {
    flog.Info(exp)  // Type does not match, will not run
})
try.CatchRefuseException(func(exp *exception.RefuseException) {
    flog.Warning(exp.Message)   // this will run
})
try.CatchException(func(exp any) {
    flog.Error(exp) // RefuseException is match, will not run
})

// print: [Warn] test is throw
try := exception.Try(func() {
    exception.ThrowRefuseException("test is throw")
})
try.CatchStringException(func(exp string) {
    flog.Info(exp)  // Type does not match, will not run
})

try.ThrowUnCatch()  // will Throw Not Match RefuseException 

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func ThrowException

func ThrowException(err string)

ThrowException 抛出Exception异常

func ThrowExceptionf

func ThrowExceptionf(format string, a ...any)

ThrowExceptionf 抛出Exception异常

func ThrowRefuseException

func ThrowRefuseException(err string)

ThrowRefuseException 抛出RefuseException异常

func ThrowRefuseExceptionBool added in v0.12.0

func ThrowRefuseExceptionBool(isTrue bool, err string)

ThrowRefuseExceptionBool 抛出RefuseException异常

func ThrowRefuseExceptionError added in v0.12.0

func ThrowRefuseExceptionError(err error)

ThrowRefuseExceptionError 抛出RefuseException异常

func ThrowRefuseExceptionf

func ThrowRefuseExceptionf(format string, a ...any)

ThrowRefuseExceptionf 抛出RefuseException异常

func ThrowRefuseExceptionfBool added in v0.12.0

func ThrowRefuseExceptionfBool(isTrue bool, format string, a ...any)

ThrowRefuseExceptionfBool 抛出RefuseException异常

func ThrowWebException

func ThrowWebException(statusCode int, err string)

ThrowWebException 抛出WebException异常

func ThrowWebExceptionBool added in v0.9.0

func ThrowWebExceptionBool(isTrue bool, statusCode int, err string)

ThrowWebExceptionBool 抛出WebException异常

func ThrowWebExceptionError added in v0.9.0

func ThrowWebExceptionError(statusCode int, err error)

ThrowWebExceptionError 抛出WebException异常

func ThrowWebExceptionf

func ThrowWebExceptionf(statusCode int, format string, a ...any)

ThrowWebExceptionf 抛出WebException异常

func ThrowWebExceptionfBool added in v0.9.0

func ThrowWebExceptionfBool(isTrue bool, statusCode int, format string, a ...any)

ThrowWebExceptionfBool 抛出WebException异常

func Try

func Try(fn func()) (catch *catchException)

Try 执行有可能发生异常的代码块

func TryCatch added in v0.14.0

func TryCatch(fn func()) error

TryCatch 异常时返回error

Types

type RefuseException

type RefuseException struct {
	// 异常信息
	Message string
}

type WebException

type WebException struct {
	// 异常信息
	Message    string
	StatusCode int
}

WebException 此异常类型在链路上不会被认定为异常,仅为业务上作为拒绝的继续往下执行的一种中断行为

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL