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 4622352
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 22, 20262026-05-22T02:49:53+00:00 2026-05-22T02:49:53+00:00

There are several questions on StackOverflow discussing the question of when one should use

  • 0

There are several questions on StackOverflow discussing the question of when one should use an assert statement versus throwing some exception. (Examples here, here, here, here, and here.

However, I have come to suspect that the conventional wisdom of assert-versus-throw is based upon the assumption that you are running within a JVM. In the GWT universe, where your Java gets transliterated to JavaScript and runs in the context of a browser, the set of tradeoffs feels different: asserts are always compiled-away when running in a browser, and anything that keeps the size of your JavaScript smaller is a win, especially if you web application must run on a mobile handset. Asserts do get run in DevMode, however, so they have utility there during development.

So my questions are: has anybody given any thought as to a set of best-practice rules that govern how to use the assert statement in GWT? I have had members of my team ask me “since the assert gets compiled out, does it make sense to have them?”, and I’d like to have a good answer for them.

Also, does anybody have any insight into the philosophy that the developers of GWT at Google have on this subject? Looking at the GWT source code, they appear to use it frequently.

  • 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-22T02:49:54+00:00Added an answer on May 22, 2026 at 2:49 am

    Google’s FAQ says

    Only use assertions for debugging purposes, not production logic because assertions will only work under GWT’s development mode. By default, they are compiled away by the GWT compiler so do not have any effect in production mode unless you explicitly enable them.

    This isn’t any different from the answers given to the questions you linked to. Whether the Java code is being compiled in the usual way by javac or being compiled to JavaScript by GWT,
    “assert” means “if this isn’t true I have a bug.” In contrast, code of the form

    if (condition) throw new Exception(msg);
    

    means “if this is true then we have an unexpected situation that the program will have to handle.”

    As for the members of the team that don’t see the point of assert, explain that they’re supposed to have a bunch of unit tests that run with assertions enabled. If the tests have good code coverage and none of them cause the assertion to fail, then the assumption indicated by the assert statement is demonstrated to hold.

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

Sidebar

Related Questions

There have been several questions already posted with specific questions about dependency injection ,
There have been several questions recently about database indexing and clustered indexing and it
There are several topics about what questions will be raised in an interview for
There are several people about (myself being one of them) who have been developing
I have found several questions and answers pertaining to my question, but I'm getting
There are several types of objects in a system, and each has it's own
There are several ways to iterate over a result set. What are the tradeoff
There are several plugin options for building a search engine into your Ruby on
There are several web applications which allow you to send photos from your mobile
There are several different methods for converting floating point numbers to Integers in JavaScript.

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.