Path: blob/master/test/hotspot/jtreg/vmTestbase/nsk/jdi/ExceptionEvent/exception/exception001a.java
41161 views
/*1* Copyright (c) 2001, 2018, Oracle and/or its affiliates. All rights reserved.2* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.3*4* This code is free software; you can redistribute it and/or modify it5* under the terms of the GNU General Public License version 2 only, as6* published by the Free Software Foundation.7*8* This code is distributed in the hope that it will be useful, but WITHOUT9* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or10* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License11* version 2 for more details (a copy is included in the LICENSE file that12* accompanied this code).13*14* You should have received a copy of the GNU General Public License version15* 2 along with this work; if not, write to the Free Software Foundation,16* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.17*18* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA19* or visit www.oracle.com if you need additional information or have any20* questions.21*/2223package nsk.jdi.ExceptionEvent.exception;2425import nsk.share.*;26import nsk.share.jpda.*;27import nsk.share.jdi.*;2829import java.lang.Integer.*;30import java.io.*;3132// This class is the debugged application in the test3334class exception001a {35static final int PASSED = 0;36static final int FAILED = 2;37static final int JCK_STATUS_BASE = 95;3839// synchronization commands40static final String COMMAND_READY = "ready";41static final String COMMAND_QUIT = "quit";42static final String COMMAND_GO = "go";43static final String COMMAND_DONE = "done";44static final String COMMAND_ERROR = "error";4546/*47// line numbers where checked exceptions thrown (for user exceptions only)48public static final int userExceptionLocation = 77;49public static final int userErrorLocation = 84;50public static final int userThrowableLocation = 91;5152// line numbers where checked exceptions caught53public static final int userExceptionCatchLocation = 79;54public static final int userErrorCatchLocation = 86;55public static final int userThrowableCatchLocation = 93;56public static final int javaExceptionCatchLocation = 100;57public static final int javaErrorCatchLocation = 107;58*/5960// flags marked all actually thrown exceptions61private static boolean userExceptionThrown = false;62private static boolean userErrorThrown = false;63private static boolean userThrowableThrown = false;64private static boolean javaExceptionThrown = false;65private static boolean javaErrorThrown = false;6667// run debuggee from command line68public static void main(String args[]) throws Throwable {69exception001a _exception001a = new exception001a();70System.exit(JCK_STATUS_BASE + _exception001a.runIt(args, System.err));71}7273// perform debuggee class execution74int runIt(String args[], PrintStream out) throws Throwable {75ArgumentHandler argHandler = new ArgumentHandler(args);76IOPipe pipe = argHandler.createDebugeeIOPipe();77Log log = new Log(out, argHandler);7879// create checked exceptions80exception001aException e1 = new exception001aException ();81exception001aError e2 = new exception001aError ();82exception001aThrowable e3 = new exception001aThrowable ();8384// notify debugger that debuggee started85pipe.println(COMMAND_READY);8687// wait for command <GO> from debugger88String command = pipe.readln();89if (!command.equals(COMMAND_GO)) {90log.complain("TEST BUG: unknown command: " + command);91return FAILED;92}9394// throw checked exceptions95try {96try {97throw new exception001aException();98} catch (exception001aException e) {99log.display("exception001aException is thrown");100userExceptionThrown = true;101}102103try {104throw new exception001aError();105} catch (exception001aError e) {106log.display("exception001aError is thrown");107userErrorThrown = true;108}109110try {111throw new exception001aThrowable();112} catch (exception001aThrowable e) {113log.display("exception001aThrowable is thrown");114userThrowableThrown = true;115}116117try {118int i = Integer.parseInt("foo");119} catch (NumberFormatException e) {120log.display("NumberFormatException is thrown");121javaExceptionThrown = true;122}123124try {125raiseStackOverflow();126} catch (StackOverflowError e) {127log.display("StackOverflowError is thrown");128javaErrorThrown = true;129}130131} catch (Throwable e) {132log.complain("Unexpected Throwable: " + e.getMessage());133e.printStackTrace();134if (e instanceof ThreadDeath) {135throw e;136}137}138139// check that all exceptions are thrown140boolean thrown = true;141if (!userExceptionThrown) {142log.complain("TEST BUG: user exception NOT thrown");143thrown = false;144}145if (!userErrorThrown) {146log.complain("TEST BUG: user error NOT thrown");147thrown = false;148}149if (!userThrowableThrown) {150log.complain("TEST BUG: user Throwable NOT thrown");151thrown = false;152}153if (!javaExceptionThrown) {154log.complain("TEST BUG: java exception NOT thrown");155thrown = false;156}157if (!javaErrorThrown) {158log.complain("TEST BUG: java error NOT thrown");159thrown = false;160}161162// notify debugger whether all exceptions thrown or not163if (thrown) {164pipe.println(COMMAND_DONE);165} else {166pipe.println(COMMAND_ERROR);167}168169// wait for command <QUIT> from debugger and exit170command = pipe.readln();171if (!command.equals(COMMAND_QUIT)) {172log.complain("TEST BUG: unknown command: " + command);173return FAILED;174}175176return PASSED;177}178179private void raiseStackOverflow () {180raiseStackOverflow();181}182}183184class exception001aException extends Exception {}185186class exception001aError extends Error {}187188class exception001aThrowable extends Throwable {}189190191