mirror of
https://github.com/tursom/GoCollections.git
synced 2025-04-02 19:00:12 +08:00
update NewRuntimeException
This commit is contained in:
parent
aad1925a1c
commit
89f1190168
@ -4,7 +4,7 @@ type ElementNotFoundException struct {
|
|||||||
RuntimeException
|
RuntimeException
|
||||||
}
|
}
|
||||||
|
|
||||||
func NewElementNotFoundException(message string, getStackTrace bool) *ElementNotFoundException {
|
func NewElementNotFoundException(message interface{}, getStackTrace bool) *ElementNotFoundException {
|
||||||
return &ElementNotFoundException{
|
return &ElementNotFoundException{
|
||||||
NewRuntimeException(
|
NewRuntimeException(
|
||||||
message,
|
message,
|
||||||
|
@ -4,7 +4,7 @@ type IndexOutOfBound struct {
|
|||||||
RuntimeException
|
RuntimeException
|
||||||
}
|
}
|
||||||
|
|
||||||
func NewIndexOutOfBound(message string, getStackTrace bool) IndexOutOfBound {
|
func NewIndexOutOfBound(message interface{}, getStackTrace bool) IndexOutOfBound {
|
||||||
return IndexOutOfBound{
|
return IndexOutOfBound{
|
||||||
NewRuntimeException(
|
NewRuntimeException(
|
||||||
message,
|
message,
|
||||||
|
@ -4,7 +4,7 @@ type NPE struct {
|
|||||||
RuntimeException
|
RuntimeException
|
||||||
}
|
}
|
||||||
|
|
||||||
func NewNPE(message string, getStackTrace bool) *NPE {
|
func NewNPE(message interface{}, getStackTrace bool) *NPE {
|
||||||
return &NPE{
|
return &NPE{
|
||||||
NewRuntimeException(
|
NewRuntimeException(
|
||||||
message,
|
message,
|
||||||
|
@ -4,7 +4,7 @@ type OperationNotSupportedException struct {
|
|||||||
RuntimeException
|
RuntimeException
|
||||||
}
|
}
|
||||||
|
|
||||||
func NewOperationNotSupportedException(message string, getStackTrace bool) OperationNotSupportedException {
|
func NewOperationNotSupportedException(message interface{}, getStackTrace bool) OperationNotSupportedException {
|
||||||
return OperationNotSupportedException{
|
return OperationNotSupportedException{
|
||||||
NewRuntimeException(
|
NewRuntimeException(
|
||||||
message,
|
message,
|
||||||
|
@ -1,6 +1,7 @@
|
|||||||
package exceptions
|
package exceptions
|
||||||
|
|
||||||
import (
|
import (
|
||||||
|
"fmt"
|
||||||
"io"
|
"io"
|
||||||
"os"
|
"os"
|
||||||
"strings"
|
"strings"
|
||||||
@ -13,7 +14,7 @@ type RuntimeException struct {
|
|||||||
cause Exception
|
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
|
var stackTrace []StackTrace = nil
|
||||||
if getStackTrace {
|
if getStackTrace {
|
||||||
stackTrace = GetStackTrace()
|
stackTrace = GetStackTrace()
|
||||||
@ -24,13 +25,20 @@ func NewRuntimeException(message, exceptionMessage string, getStackTrace bool, c
|
|||||||
}
|
}
|
||||||
|
|
||||||
var causeException Exception = nil
|
var causeException Exception = nil
|
||||||
switch cause.(type) {
|
if cause != nil {
|
||||||
case Exception:
|
switch cause.(type) {
|
||||||
causeException = cause.(Exception)
|
case Exception:
|
||||||
|
causeException = cause.(Exception)
|
||||||
|
default:
|
||||||
|
causeException = RuntimeException{
|
||||||
|
message: fmt.Sprint(cause),
|
||||||
|
exceptionMessage: "exception caused:",
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
return RuntimeException{
|
return RuntimeException{
|
||||||
message: message,
|
message: fmt.Sprint(message),
|
||||||
exceptionMessage: exceptionMessage,
|
exceptionMessage: exceptionMessage,
|
||||||
stackTrace: stackTrace,
|
stackTrace: stackTrace,
|
||||||
cause: causeException,
|
cause: causeException,
|
||||||
|
5
main.go
5
main.go
@ -13,12 +13,11 @@ func main() {
|
|||||||
fmt.Println("recover from panic", r)
|
fmt.Println("recover from panic", r)
|
||||||
return nil, exceptions.NewIndexOutOfBound(fmt.Sprint(r), true)
|
return nil, exceptions.NewIndexOutOfBound(fmt.Sprint(r), true)
|
||||||
})
|
})
|
||||||
exception := err.(exceptions.Exception)
|
|
||||||
exceptions.NewRuntimeException(
|
exceptions.NewRuntimeException(
|
||||||
exception.Error(),
|
err,
|
||||||
"test exception:",
|
"test exception:",
|
||||||
true,
|
true,
|
||||||
exception,
|
err,
|
||||||
).PrintStackTrace()
|
).PrintStackTrace()
|
||||||
|
|
||||||
list := collections.NewArrayList()
|
list := collections.NewArrayList()
|
||||||
|
Loading…
Reference in New Issue
Block a user