diff --git a/exceptions/ElementNotFound.go b/exceptions/ElementNotFound.go index 1baee3c..5ca9800 100644 --- a/exceptions/ElementNotFound.go +++ b/exceptions/ElementNotFound.go @@ -4,7 +4,7 @@ type ElementNotFoundException struct { RuntimeException } -func NewElementNotFoundException(message string, getStackTrace bool) *ElementNotFoundException { +func NewElementNotFoundException(message interface{}, getStackTrace bool) *ElementNotFoundException { return &ElementNotFoundException{ NewRuntimeException( message, diff --git a/exceptions/IndexOutOfBoundError.go b/exceptions/IndexOutOfBoundError.go index 158ac37..d123887 100644 --- a/exceptions/IndexOutOfBoundError.go +++ b/exceptions/IndexOutOfBoundError.go @@ -4,7 +4,7 @@ type IndexOutOfBound struct { RuntimeException } -func NewIndexOutOfBound(message string, getStackTrace bool) IndexOutOfBound { +func NewIndexOutOfBound(message interface{}, getStackTrace bool) IndexOutOfBound { return IndexOutOfBound{ NewRuntimeException( message, diff --git a/exceptions/NPE.go b/exceptions/NPE.go index fb4dfa2..ac1ed35 100644 --- a/exceptions/NPE.go +++ b/exceptions/NPE.go @@ -4,7 +4,7 @@ type NPE struct { RuntimeException } -func NewNPE(message string, getStackTrace bool) *NPE { +func NewNPE(message interface{}, getStackTrace bool) *NPE { return &NPE{ NewRuntimeException( message, diff --git a/exceptions/OperationNotSupportedException.go b/exceptions/OperationNotSupportedException.go index 688c51b..634183a 100644 --- a/exceptions/OperationNotSupportedException.go +++ b/exceptions/OperationNotSupportedException.go @@ -4,7 +4,7 @@ type OperationNotSupportedException struct { RuntimeException } -func NewOperationNotSupportedException(message string, getStackTrace bool) OperationNotSupportedException { +func NewOperationNotSupportedException(message interface{}, getStackTrace bool) OperationNotSupportedException { return OperationNotSupportedException{ NewRuntimeException( message, diff --git a/exceptions/RuntimeException.go b/exceptions/RuntimeException.go index 6bebe0d..73762f1 100644 --- a/exceptions/RuntimeException.go +++ b/exceptions/RuntimeException.go @@ -1,6 +1,7 @@ package exceptions import ( + "fmt" "io" "os" "strings" @@ -13,7 +14,7 @@ type RuntimeException struct { cause Exception } -func NewRuntimeException(message, exceptionMessage string, getStackTrace bool, cause interface{}) RuntimeException { +func NewRuntimeException(message interface{}, exceptionMessage string, getStackTrace bool, cause interface{}) RuntimeException { var stackTrace []StackTrace = nil if getStackTrace { stackTrace = GetStackTrace() @@ -24,13 +25,20 @@ func NewRuntimeException(message, exceptionMessage string, getStackTrace bool, c } var causeException Exception = nil - switch cause.(type) { - case Exception: - causeException = cause.(Exception) + if cause != nil { + switch cause.(type) { + case Exception: + causeException = cause.(Exception) + default: + causeException = RuntimeException{ + message: fmt.Sprint(cause), + exceptionMessage: "exception caused:", + } + } } return RuntimeException{ - message: message, + message: fmt.Sprint(message), exceptionMessage: exceptionMessage, stackTrace: stackTrace, cause: causeException, diff --git a/main.go b/main.go index 991dbcb..386f81f 100644 --- a/main.go +++ b/main.go @@ -13,12 +13,11 @@ func main() { fmt.Println("recover from panic", r) return nil, exceptions.NewIndexOutOfBound(fmt.Sprint(r), true) }) - exception := err.(exceptions.Exception) exceptions.NewRuntimeException( - exception.Error(), + err, "test exception:", true, - exception, + err, ).PrintStackTrace() list := collections.NewArrayList()