Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 4537280
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 21, 20262026-05-21T14:39:13+00:00 2026-05-21T14:39:13+00:00

Conventional wisdom says you can only throw objects that extend Throwable in Java, but

  • 0

Conventional wisdom says you can only throw objects that extend Throwable in Java, but is it possible to disable the bytecode verifier and get Java to compile and run code that throws arbitrary objects – or even primitives?

I looked up the JVM’s athrow and it will pop the first objref on the operand stack; but would it check if said reference points to a Throwable at run time?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-21T14:39:13+00:00Added an answer on May 21, 2026 at 2:39 pm

    It depends on your JVM implementation. According to the Java VM specification it is undefined behavior if the object is not Throwable.

    The objectref must be of type reference and must refer to an object that is an instance of class Throwable or of a subclass of Throwable.

    In section 6.1, “The Meaning of ‘Must'”:

    If some constraint (a “must” or “must not”) in an instruction description is not satisfied at run time, the behavior of the Java virtual machine is undefined.

    I wrote a test program using the Jasmin assembler which does the equivalent of throw new Object(). The Java HotSpot Server VM throws a VerifyError:

    # cat Athrow.j 
    .source Athrow.j
    .class public Athrow
    .super java/lang/Object
    
    .method public <init>()V
        aload_0
        invokenonvirtual java/lang/Object/<init>()V
        return
    .end method
    
    .method public static main([Ljava/lang/String;)V
        .limit stack 2
    
        new java/lang/Object
        dup
        invokenonvirtual java/lang/Object/<init>()V
        athrow
    
        return
    .end method
    
    # java -jar jasmin.jar Athrow.j 
    Generated: Athrow.class
    
    # java Athrow
    Exception in thread "main" java.lang.VerifyError: (class: Athrow, method: main signature: ([Ljava/lang/String;)V) Can only throw Throwable objects
    

    Disabling the bytecode verifier allows the athrow to execute and the JVM appears to crash when it tries to print the exception’s details. Compare these two programs, the first which throws an Exception, the second which is the above test program which throws an Object. Notice how it exits in the middle of a printout:

    # java -Xverify:none examples/Uncaught
    Exception in thread "main" java.lang.Exception
            at examples.Uncaught.main(Uncaught.j)
    # java -Xverify:none Athrow
    Exception in thread "main" #
    

    Of course, disabling the bytecode verifier is dangerous. The VM proper is written to assume that bytecode verification has been performed and therefore does not have to typecheck instruction operands. Beware: the undefined behavior that you invoke when you circumvent bytecode verification is much like the undefined behavior in C programs; anything at all can happen, including demons flying out of your nose.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Conventional wisdom tells us that high-volume enterprise java applications should use thread pooling in
Conventional wisdom states that stored procedures are always faster. So, since they're always faster,
Question: Is exception handling in Java actually slow? Conventional wisdom, as well as a
I've only written a small amount of JavaScript that runs embedded in a Java
I have an ASP.NET MVC 2 project that renders conventional strongly typed pages, but
Or would a conventional client-server VCS be more appropriate? I'm currently using TortoiseSVN, but
What is Couch DB? How is that different from conventional oracle DB? What is
Conventional IPv4 dotted quad notation separates the address from the port with a colon,
If you use an EnumSet to store conventional binary values (1,2,4 etc), then when
In the Fibonacci sequence, I have seen conventional implementations which recursively call the same

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.