I originally thought that exceptions are classes with code that can handle exceptions, so a class that extends Exception should also inherit child methods(
which are supposedly algos/mechanisms to detect exceptions), but I guess I was wrong.
When I looked at the source code, pretty much all the <? extends Throwable> classes do are calling the super constructors. So when you are creating a custom exception:
1. You are only creating a new detection mechanism for business or logical exceptions, not new [
machine level]exception detection mechanisms.
2. You want to override the default exceptions.
There was also the concept of inheritance that I forgot to apply when reading exceptions.
Cat < Mammal < Animal
Lizard < Animal
Cat is not a Lizard
AIOOB < RuntimeException < Exception
MyException < Exception
AIOOB is not a MyException
From the information that I have gathered so far, Java exception classes are just high level abstraction sugar that translate real exceptions into human-readable form. The HotSpot JVM is maybe using c++ features to catch the exceptions, c++ is maybe using something else, and the chain goes on until you reach machine code. An exception is thrown if the JVM returns 'athrow', I guess.
https://www.infoworld.com/article/20768 ... tions.html
Hypothetically, the chain of error throwing is maybe be something like this:
Code: Select all
CPU > exception or machine language? > jvm > athrow
or like this:
Code: Select all
Jvm checks for exception before passing instruction to CPU using internal c++ code > athrow
or like this:
Code: Select all
Jvm uses Operating System features for check/handle exceptions > athrow
Obviously, if an exception is not caught by either the JVM or the CPU's detection mechanism, then the CPU might hang.
https://softwareengineering.stackexchan ... de-by-zero
I guess a lot of CPU exploits look for illegal instructions that are unchecked by either the OS or the CPU itself? I'm no hacker, but after reading through this low level exception stuff, I was able to deduce some assumptions about this topic.
The above scenarios are only hypothetical and understanding this process at a low level is probably out of scope for the exam. So I don't want to dive too deep into this topic. The important thing here is to understand what the exception classes do from a 'Java' level, not how this process works under the hood.
I was confused between multiple concepts, what exception classes source codes really do, logical/business exceptions vs machine-level exceptions, and inheritance.
I think I understand Java exceptions very well now. Thanks.