0N/A/*
2362N/A * Copyright (c) 2003, Oracle and/or its affiliates. All rights reserved.
0N/A * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
0N/A *
0N/A * This code is free software; you can redistribute it and/or modify it
0N/A * under the terms of the GNU General Public License version 2 only, as
2362N/A * published by the Free Software Foundation. Oracle designates this
0N/A * particular file as subject to the "Classpath" exception as provided
2362N/A * by Oracle in the LICENSE file that accompanied this code.
0N/A *
0N/A * This code is distributed in the hope that it will be useful, but WITHOUT
0N/A * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
0N/A * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
0N/A * version 2 for more details (a copy is included in the LICENSE file that
0N/A * accompanied this code).
0N/A *
0N/A * You should have received a copy of the GNU General Public License version
0N/A * 2 along with this work; if not, write to the Free Software Foundation,
0N/A * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
0N/A *
2362N/A * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
2362N/A * or visit www.oracle.com if you need additional information or have any
2362N/A * questions.
0N/A */
0N/A
0N/A/*
0N/A * Copyright 2003 Wily Technology, Inc.
0N/A */
0N/A
0N/A#ifndef _JAVAEXCEPTIONS_H_
0N/A#define _JAVAEXCEPTIONS_H_
0N/A
0N/A#include <jni.h>
0N/A#include <jvmti.h>
0N/A
0N/A/**
0N/A * This module contains utility routines for manipulating Java throwables
0N/A * and JNIEnv throwable state from native code.
0N/A */
0N/A
0N/A#ifdef __cplusplus
0N/Aextern "C" {
0N/A#endif
0N/A
0N/A/*
0N/A * Set up static state. Needs java, must be called at or after VMInit.
0N/A * Returns true if it succeeds, false if it fails.
0N/A */
0N/Aextern jboolean
0N/AinitializeFallbackError(JNIEnv* jnienv);
0N/A
0N/A/*
0N/A * Mapping support. Allows different clients to map checked exceptions in different ways.
0N/A */
0N/Atypedef jthrowable (*CheckedExceptionMapper)
0N/A ( JNIEnv * jnienv,
0N/A jthrowable throwableToMap);
0N/A
0N/A/* Default mapper. Map everything checked to InternalError; can return null if error */
0N/Aextern jthrowable
0N/AmapAllCheckedToInternalErrorMapper( JNIEnv * jnienv,
0N/A jthrowable throwableToMap);
0N/A
0N/A
0N/A
0N/A/*
0N/A * Exception-helper routines that do not modify the JNIEnv.
0N/A * They require a clean JNIEnv on entry, and they guarantee a clean JNIEnv on exit.
0N/A */
0N/A
0N/A/* creates a throwable from the supplied parameters; can return null if error */
0N/Aextern jthrowable
0N/AcreateThrowable( JNIEnv* jnienv,
0N/A const char* className,
0N/A jstring message);
0N/A
0N/A/* creates a java.lang.InternalError; can return null if error */
0N/Aextern jthrowable
0N/AcreateInternalError(JNIEnv * jnienv, jstring message);
0N/A
0N/A/* creates the appropriate java Throwable based on the error code; can return null if error */
0N/Aextern jthrowable
0N/AcreateThrowableFromJVMTIErrorCode(JNIEnv * jnienv, jvmtiError errorCode);
0N/A
0N/A/* fetches the message string out of the supplied throwable, null if there is none, null if error */
0N/Aextern jstring
0N/AgetMessageFromThrowable( JNIEnv* jnienv,
0N/A jthrowable exception);
0N/A
0N/A/* true if the supplied throwable is unchecked. null will return true. */
0N/Aextern jboolean
0N/AisUnchecked( JNIEnv* jnienv,
0N/A jthrowable exception);
0N/A
0N/A/* true if the env contains a thrown exception */
0N/Aextern jboolean
0N/AcheckForThrowable( JNIEnv* jnienv);
0N/A
0N/A/* true if the env is clean for JNI calls */
0N/Aextern jboolean
0N/AisSafeForJNICalls( JNIEnv * jnienv);
0N/A
0N/A/*
0N/A * Logs the outstanding throwable, if one exists.
0N/A * This call assumes an outstanding exception, but does not
0N/A * modify the JNIEnv outstanding Throwable state.
0N/A */
0N/Aextern void
0N/AlogThrowable( JNIEnv * jnienv);
0N/A
0N/A
0N/A/*
0N/A * These routines do modify the JNIEnv outstanding Throwable state.
0N/A */
0N/A
0N/A/* Throws the supplied throwable. always sets the JNIEnv throwable */
0N/Aextern void
0N/AthrowThrowable( JNIEnv * jnienv,
0N/A jthrowable exception);
0N/A
0N/A/* returns current throwable. always clears the JNIEnv exception */
0N/Aextern jthrowable
0N/ApreserveThrowable(JNIEnv * jnienv);
0N/A
0N/A/* undoes preserveThrowable (Throws the supplied throwable). always sets the JNIEnv throwable */
0N/Aextern void
0N/ArestoreThrowable( JNIEnv * jnienv,
0N/A jthrowable preservedException);
0N/A
0N/A/* always clears the JNIEnv throwable. returns true if an exception was pending on entry. */
0N/Aextern jboolean
0N/AcheckForAndClearThrowable( JNIEnv * jnienv);
0N/A
0N/A/* creates the appropriate java Throwable based on the error code
0N/A * does the very best it can to make sure an exception ends up installed; uses fallback if necessary
0N/A * always sets the JNIEnv exception
0N/A */
0N/Aextern void
0N/AcreateAndThrowThrowableFromJVMTIErrorCode(JNIEnv * jnienv, jvmtiError errorCode);
0N/A
0N/A/* creates a java.lang.InternalError and installs it into the JNIEnv.
0N/A * does the very best it can to make sure an exception ends up installed; uses fallback if necessary
0N/A * always sets the JNIEnv exception
0N/A */
0N/Aextern void
0N/AcreateAndThrowInternalError(JNIEnv * jnienv);
0N/A
0N/A/* If no throwable is outstanding, do nothing.
0N/A * If a throwable is outstanding, make sure it is of a legal type according to the supplied
0N/A * mapping function.
0N/A * Leaves the "thrown" state the same (none on exit if none on entry, thrown on exit if
0N/A * thrown on entry); may change the type of the thrown exception.
0N/A */
0N/Aextern void
0N/AmapThrownThrowableIfNecessary(JNIEnv * jnienv, CheckedExceptionMapper mapper);
0N/A
0N/A#ifdef __cplusplus
0N/A} /* extern "C" */
0N/A#endif /* __cplusplus */
0N/A
0N/A
0N/A#endif