Thursday 6 December 2012

EXCEPTION HANDLING....CONT123

EXCEPTION HANDLING....CONT123
TYPES OF ASSERT STATEMENT:-
   There are two kinds of assert stmts
1) Easy version
2) Enhanced version

   SIMPLE VERSION:
Syntax:- assert(b);

    If b is real our supposition is reliable and relax of the our supposition isn't able and the relax of the value will never be executed and ends the system unusually by improving declaration mistake.

class AssertEX1 {
public fixed gap main(string[] args) {
int x=10;
;;;;;;
assert(x>10);
;;;;;;
System.out.println(x);
}
}

OUTPUT:-
>javac AssertEX1.java
>java AssertEX2
o/p [because declaration are impaired by standard and assert claims will never be executed]
>java -ea AssertEX1
Runtime exemption saying AssertionError

AUGMENTED VERSION:-
Assert(b):e;
We can add some information to say stmt by Boolean kind. And 'e' can be any kind of factor.
ClassTest{
Public fixed gap main(String [] args) {
int x=10;
;;;;;;
assert(x>10); // it is incorrect due to x;
;;;;;;
System.out.println(x);
}
}

OUTPUT:-
>javac Analyze.java
>java Test
10
>java -ea Test
RuntimeException: AssertionError : it is incorrect due to x.

No comments:

Post a Comment