Q:

why I am getting two different values from system.out.println() and system.exit()?

System.out.println(Integer.parseInt(e.getMessage()));
System.out.println(e.getMessage());
System.exit(Integer.parseInt(e.getMessage()));

when I am runnig the code in unix system.exit(Integer.parseInt(e.getMessage())) is giving 254 
output:
-2  
-2  
254

A:

Your operating system's exit codes are unsigned 8-bit integers, so the only valid exit codes are 0..255.
The reason you are getting 254 is because it's the lower 8 bits of int -2 treated as an unsigned number.
$ for q in -2 -1 0 1 2 253 254 255 256 257 ; do
   perl -e'exit $ARGV[0]' -- $q
   printf '%3d => %3d\n' $q $?
done
 -2 => 254
 -1 => 255
  0 =>   0
  1 =>   1
  2 =>   2
253 => 253
254 => 254
255 => 255
256 =>   0
257 =>   1

