answersLogoWhite

0


Best Answer

Suppose you assume that a number passed into a method (say, methodOne()) will never be negative. While testing and debugging, you want to validate your assumption, but you don't want to have to strip out print statements, runtime exception handlers, or if/else tests when you're done with development. But leaving any of those in is, at the least, a performance hit. Assertions to the rescue!

Assertions work quite simply. You always assert that something is true. If it is, no problem. Code keeps running. But if your assertion turns out to be wrong (false), then a AssertionError is thrown right then and there, so you can fix whatever logic flaw led to the problem. Assertions come in two flavors: really simple and simple, as follows: Really simple: private void doSomething() { assert (y > x); // more code assuming y is greater than x } Simple: private void doSomething() { assert (y > x): "y is " + y + " x is " + x; // more code assuming y is greater than x }

User Avatar

Wiki User

10y ago
This answer is:
User Avatar

Add your answer:

Earn +20 pts
Q: What the various types of assert methods and it purpose?
Write your answer...
Submit
Still have questions?
magnify glass
imp
Related questions

What are the types of social research?

there are three types of social research. 1) According methods/ purpose. 2) According to use. 3) According to series time.


What are the types of communication methods?

types of communication methods?


What methods can one use to locate a particular address?

There are many methods to locating a particular address in today's modern society. A few of the methods one could try are magazines, newspapers and the phone book. There are also many apps out for various types of modern phones.


What is the purpose of an exchange host?

The purpose of exchange hosting is a server system that enables the receiving and sending of emails, various types of interactive communications and sharing of critical business information online.


Explain the various types of conflict?

various types of audit


Digital integrated circuit use various types of what to achieve their purpose of operation?

Transistors and electronic miniature components packaged into a small case.


What is versatile computer?

versatility of computer means that the computer is able to perform various types of functions or operations.


Briefly explain various types of insurance?

various types of insurance


What are the types and methods of pricing?

asfsdfdsfa


What are the Various types of index used in India?

what are the various types of index in India


How do you remove paint from plastic oven control panel?

Ovens can be cleaned with various types of methods. Ovens can be cleaned with gas or electric, self-cleaning, and even continuously cleaning.


How many methods of liver transplantation are there?

There are three types of liver transplantation methods.