How Can I Force Execution to the Catch Block?

   try{
      if (AnyConditionTrue){
              //run some code
               }
      else{
              throw new Exception();
          }
   }
   catch(){

      //run some code here...

   }

But like Yuck has stated, I wouldn’t recommend this. You should take a step back at your design and what you’re looking to accomplish. There’s a better way to do it (i.e. with normal conditional flow, instead of exception handling).

Leave a Comment