mirror of
https://github.com/tursom/GoCollections.git
synced 2024-12-27 17:10:25 +08:00
update NewRuntimeException
This commit is contained in:
parent
aad1925a1c
commit
89f1190168
@ -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,
|
||||
|
@ -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,
|
||||
|
@ -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,
|
||||
|
@ -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,
|
||||
|
@ -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,
|
||||
|
5
main.go
5
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()
|
||||
|
Loading…
Reference in New Issue
Block a user