how to code with debug options in java
<p>I am trying to learn the trick on how to run the code which prints a lot of stuff when the debug flag is on.</p>

<p>How is that done in java. </p>

<p>A very naive way I can think of is have the debug flag in all the methods i write</p>

<p>and write something like</p>

<pre><code> if (this.debug == true){
 System.out.println("blah blah");
  }
</code></pre>

<p>But there should be much more elegant way rather than having all these ifs in code?</p>

<p>Also, is there a way I can get the line number of certain execution in code:</p>

<p>For example if there is an exception</p>

<pre><code>            try:
</code></pre>

<p>/* line number 22 */  </p>

<pre><code> catch Exception e{
         //print that exception occured in above line number??
    }
</code></pre>

<p>Probably very lame questions.
THanks</p>
