Display the First image from a Posts

function catch_that_image() {
  global $post, $posts;
  $first_img = get_post_meta($post->ID, 'thumb', true);
  ob_start();
  ob_end_clean();
  $output = preg_match_all('/<img.+src=[\'
"]([^\'"]+)[\'"].*>/i', $post->post_content, $matches);
  if($output == 1 && empty($first_img)){ //Defines a default image
  $first_img = $matches [1][0];
  }
  else if(empty($first_img) && $output == 0) { $first_img = "no_image_url";
  }
  return $first_img;
}
Advertisements

Catch Exception in Java

Sample code that shows how the catch works.

File:ex.java

class ex
{
public static void main(String ar[])
{
int a[]={2,3};
try
{
a[2]=5;
System.out.println(“The Value is added to the index”);
}
catch(Exception e)
{
System.out.println(“Genereated Exception ” +e);
}
}
}

Output:
Genereated Exception java.lang.ArrayIndexOutOfBoundsException: 2