Skip to content

Commit

Permalink
JACOBIN-401 Added initial output for uncaught exception in ATHROW
Browse files Browse the repository at this point in the history
  • Loading branch information
platypusguy committed Nov 21, 2023
1 parent 049d077 commit e9df3d2
Show file tree
Hide file tree
Showing 2 changed files with 31 additions and 1 deletion.
15 changes: 15 additions & 0 deletions src/exceptions/errors.go
Original file line number Diff line number Diff line change
Expand Up @@ -168,3 +168,18 @@ func ShowGoStackTrace(stackInfo any) {
}
global.GoStackShown = true
}

// GetExceptionNameFromClassName extracts the name of the exception from the name of the exception class
func GetExceptionNameFromClassName(className string) string {
var excName = ""

// if it's not an excepted exception or error class name, return an empty string
if !strings.HasSuffix(className, "xception") && !strings.HasSuffix(className, "rror") {
return ""
}

lastSlash := strings.LastIndex(className, "/")
excName = className[lastSlash+1:]

return excName
}
17 changes: 16 additions & 1 deletion src/jvm/run.go
Original file line number Diff line number Diff line change
Expand Up @@ -2278,7 +2278,7 @@ func runFrame(fs *list.List) error {
case opcodes.ATHROW: // 0xBF throw an exception
// points to an instance of the error/exception class
// that's being thrown
objectRef := pop(f)
objectRef := pop(f).(*object.Object)
if object.IsNull(objectRef) {
errMsg := "ATHROW: Invalid (null) reference to a exception/error class to throw"
exceptions.Throw(exceptions.NullPointerException, errMsg)
Expand All @@ -2293,6 +2293,21 @@ func runFrame(fs *list.List) error {
// capture the JVM frame stack
glob.JVMframeStack = exceptions.GrabFrameStack(fs)

// get the name of the exception in the format used by HotSpot
exceptionClass := *objectRef.Klass
exceptionName := strings.Replace(exceptionClass, "/", ".", -1)

// print out the data, as we have it presently
_ = log.Log("Exception in thread "+exceptionName+":", log.SEVERE)
for _, frameData := range *glob.JVMframeStack {
colon := strings.Index(frameData, ":")
shortenedFrameData := frameData[colon+1:]
_ = log.Log("\t at"+shortenedFrameData, log.SEVERE)
}

// all exceptions that got this far are untrapped, so shutdown with an error code
shutdown.Exit(shutdown.APP_EXCEPTION)

case opcodes.CHECKCAST: // 0xC0 same as INSTANCEOF but throws exception on null
// because this uses the same logic as INSTANCEOF, any change here should
// be made to INSTANCEOF
Expand Down

0 comments on commit e9df3d2

Please sign in to comment.