update NewRuntimeException

This commit is contained in:
tursom 2021-05-21 11:25:53 +08:00
parent aad1925a1c
commit 89f1190168
6 changed files with 19 additions and 12 deletions

View File

@ -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,

View File

@ -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,

View File

@ -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,

View File

@ -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,

View File

@ -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,

View File

@ -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()