github.com/tursom/GoCollections@v0.3.10/lang/ExceptionConfig.go (about) 1 /* 2 * Copyright (c) 2022 tursom. All rights reserved. 3 * Use of this source code is governed by a GPL-3 4 * license that can be found in the LICENSE file. 5 */ 6 7 package lang 8 9 type ExceptionConfig struct { 10 SkipStack int 11 GetStackTrace bool 12 Cause any 13 ExceptionName string 14 } 15 16 func Cfg() *ExceptionConfig { 17 return DefaultExceptionConfig() 18 } 19 20 func DefaultExceptionConfig() *ExceptionConfig { 21 return &ExceptionConfig{ 22 SkipStack: 0, 23 GetStackTrace: true, 24 Cause: nil, 25 } 26 } 27 28 func (c *ExceptionConfig) SetSkipStack(skipStack int) *ExceptionConfig { 29 if c == nil { 30 return &ExceptionConfig{SkipStack: skipStack, GetStackTrace: true} 31 } 32 c.SkipStack = skipStack 33 return c 34 } 35 36 func (c *ExceptionConfig) SetGetStackTrace(getStackTrace bool) *ExceptionConfig { 37 if c == nil { 38 return &ExceptionConfig{GetStackTrace: getStackTrace} 39 } 40 c.GetStackTrace = getStackTrace 41 return c 42 } 43 44 func (c *ExceptionConfig) SetCause(cause any) *ExceptionConfig { 45 if c == nil { 46 return &ExceptionConfig{Cause: cause, GetStackTrace: true} 47 } 48 c.Cause = cause 49 return c 50 } 51 52 func (c *ExceptionConfig) AddSkipStack(skipStack int) *ExceptionConfig { 53 if c == nil { 54 return &ExceptionConfig{SkipStack: skipStack, GetStackTrace: true} 55 } 56 c.SkipStack += skipStack 57 return c 58 } 59 60 func (c *ExceptionConfig) SetExceptionName(exceptionName string) *ExceptionConfig { 61 if c == nil { 62 return &ExceptionConfig{ExceptionName: exceptionName, GetStackTrace: true} 63 } 64 c.ExceptionName = exceptionName 65 return c 66 }