Why the byte code is generated as
.annotation system Ldalvik/annotation/Throws;
value = {
Ljava/io/FileNotFoundException;
}
.end annotation
rather than .throws Ljava/io/FileNotFoundException
if a method declares throws FileNotFoundException
in the header in java code?
The short answer is that there is no specific "throws" concept in the dex format. When a java classfile is converted to the dex format, a Throws annotation is added that contains this information.
Slightly longer answer:
The concept of a checked exception only matters at compile time, not at runtime. The dalvik virtual machine doesn't know about or care what exceptions your method can throw. As far as it is concerned, everything is an unchecked exception. It's the java compiler that enforces that checked exceptions are declared in your throws clause.
As such, it doesn't make sense to add a specific "throws" concept to the dex file. Instead, that information is stored using the more generic annotation feature.
It sounds like you are using something like dex2jar to convert a dex file back to a set of class file and then using jasmin on it. It's likely that dex2jar doesn't remap the Throws annotations from the dex file back to the Exception attribute in the classfile, although I haven't specifically checked whether that is the case.
dalvik.annotation.Throws appears on methods
A Throws annotation is attached to each method which is declared to throw one or more exception types.
At the bottom of this page.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With