1 /* 2 * Copyright (c) 2021 Huawei Device Co., Ltd. 3 * Licensed under the Apache License, Version 2.0 (the "License"); 4 * you may not use this file except in compliance with the License. 5 * You may obtain a copy of the License at 6 * 7 * http://www.apache.org/licenses/LICENSE-2.0 8 * 9 * Unless required by applicable law or agreed to in writing, software 10 * distributed under the License is distributed on an "AS IS" BASIS, 11 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 * See the License for the specific language governing permissions and 13 * limitations under the License. 14 */ 15 16 #ifndef PANDA_RUNTIME_INCLUDE_EXCEPTIONS_H_ 17 #define PANDA_RUNTIME_INCLUDE_EXCEPTIONS_H_ 18 19 #include "runtime/include/class-inl.h" 20 #include "runtime/include/coretypes/array.h" 21 #include "runtime/include/language_context.h" 22 #include "runtime/include/method.h" 23 24 namespace panda { 25 26 void ThrowException(LanguageContext ctx, ManagedThread *thread, const uint8_t *mutf8_name, const uint8_t *mutf8_msg); 27 28 void ThrowNullPointerException(); 29 // This function could be used in case there are no managed stack frames. 30 // For example when the main thread creates an instance of VM and calls 31 // a JNI function which throws an exception. In this case there is no need to 32 // get current executing method from the managed stack. 33 void ThrowNullPointerException(LanguageContext ctx, ManagedThread *thread); 34 35 void ThrowArrayIndexOutOfBoundsException(coretypes::array_ssize_t idx, coretypes::array_size_t length); 36 void ThrowArrayIndexOutOfBoundsException(coretypes::array_ssize_t idx, coretypes::array_size_t length, 37 LanguageContext ctx, ManagedThread *thread); 38 39 void ThrowIndexOutOfBoundsException(coretypes::array_ssize_t idx, coretypes::array_ssize_t length); 40 41 void ThrowIllegalStateException(const PandaString &msg); 42 43 void ThrowStringIndexOutOfBoundsException(coretypes::array_ssize_t idx, coretypes::array_size_t length); 44 45 void ThrowNegativeArraySizeException(coretypes::array_ssize_t size); 46 47 void ThrowNegativeArraySizeException(const PandaString &msg); 48 49 void ThrowArithmeticException(); 50 51 void ThrowClassCastException(Class *dst_type, Class *src_type); 52 53 void ThrowAbstractMethodError(Method *method); 54 55 void ThrowArrayStoreException(Class *array_class, Class *element_class); 56 57 void ThrowArrayStoreException(const PandaString &msg); 58 59 void ThrowRuntimeException(const PandaString &msg); 60 61 void ThrowFileNotFoundException(const PandaString &msg); 62 63 void ThrowIOException(const PandaString &msg); 64 65 void ThrowIllegalArgumentException(const PandaString &msg); 66 67 void ThrowClassCircularityError(const PandaString &class_name, LanguageContext ctx); 68 69 void ThrowOutOfMemoryError(ManagedThread *thread, const PandaString &msg); 70 71 void ThrowOutOfMemoryError(const PandaString &msg); 72 73 void FindCatchBlockInCallStack(ObjectHeader *exception); 74 75 void FindCatchBlockInCFrames(ObjectHeader *exception, StackWalker *stack, Frame *orig_frame); 76 77 void ThrowIllegalAccessException(const PandaString &msg); 78 79 void ThrowUnsupportedOperationException(); 80 81 void ThrowVerificationException(const PandaString &msg); 82 83 void ThrowVerificationException(LanguageContext ctx, const PandaString &msg); 84 85 void ThrowInstantiationError(const PandaString &msg); 86 87 void ThrowNoClassDefFoundError(const PandaString &msg); 88 89 void ThrowTypedErrorDyn(const std::string &msg); 90 91 void ThrowReferenceErrorDyn(const std::string &msg); 92 93 void ThrowIllegalMonitorStateException(const PandaString &msg); 94 95 } // namespace panda 96 97 #endif // PANDA_RUNTIME_INCLUDE_EXCEPTIONS_H_ 98