<?xml version="1.0"?>
<feed xmlns="http://www.w3.org/2005/Atom" xml:lang="ru">
		<id>http://www.jexp.ru/index.php?action=history&amp;feed=atom&amp;title=Java_Tutorial%2FStatement_Control%2Ftry_catch</id>
		<title>Java Tutorial/Statement Control/try catch - История изменений</title>
		<link rel="self" type="application/atom+xml" href="http://www.jexp.ru/index.php?action=history&amp;feed=atom&amp;title=Java_Tutorial%2FStatement_Control%2Ftry_catch"/>
		<link rel="alternate" type="text/html" href="http://www.jexp.ru/index.php?title=Java_Tutorial/Statement_Control/try_catch&amp;action=history"/>
		<updated>2026-04-23T14:19:47Z</updated>
		<subtitle>История изменений этой страницы в вики</subtitle>
		<generator>MediaWiki 1.30.0</generator>

	<entry>
		<id>http://www.jexp.ru/index.php?title=Java_Tutorial/Statement_Control/try_catch&amp;diff=5244&amp;oldid=prev</id>
		<title>Admin: 1 версия</title>
		<link rel="alternate" type="text/html" href="http://www.jexp.ru/index.php?title=Java_Tutorial/Statement_Control/try_catch&amp;diff=5244&amp;oldid=prev"/>
				<updated>2010-06-01T05:18:56Z</updated>
		
		<summary type="html">&lt;p&gt;1 версия&lt;/p&gt;
&lt;table class=&quot;diff diff-contentalign-left&quot; data-mw=&quot;interface&quot;&gt;
				&lt;tr style=&quot;vertical-align: top;&quot; lang=&quot;ru&quot;&gt;
				&lt;td colspan=&quot;1&quot; style=&quot;background-color: white; color:black; text-align: center;&quot;&gt;← Предыдущая&lt;/td&gt;
				&lt;td colspan=&quot;1&quot; style=&quot;background-color: white; color:black; text-align: center;&quot;&gt;Версия 05:18, 1 июня 2010&lt;/td&gt;
				&lt;/tr&gt;&lt;tr&gt;&lt;td colspan=&quot;2&quot; style=&quot;text-align: center;&quot; lang=&quot;ru&quot;&gt;&lt;div class=&quot;mw-diff-empty&quot;&gt;(нет различий)&lt;/div&gt;
&lt;/td&gt;&lt;/tr&gt;&lt;/table&gt;</summary>
		<author><name>Admin</name></author>	</entry>

	<entry>
		<id>http://www.jexp.ru/index.php?title=Java_Tutorial/Statement_Control/try_catch&amp;diff=5243&amp;oldid=prev</id>
		<title> в 17:44, 31 мая 2010</title>
		<link rel="alternate" type="text/html" href="http://www.jexp.ru/index.php?title=Java_Tutorial/Statement_Control/try_catch&amp;diff=5243&amp;oldid=prev"/>
				<updated>2010-05-31T17:44:27Z</updated>
		
		<summary type="html">&lt;p&gt;&lt;/p&gt;
&lt;p&gt;&lt;b&gt;Новая страница&lt;/b&gt;&lt;/p&gt;&lt;div&gt;==  An example of nested try statements. ==&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
   &lt;br /&gt;
  &amp;lt;!-- start source code --&amp;gt;&lt;br /&gt;
   &lt;br /&gt;
    &amp;lt;source lang=&amp;quot;java&amp;quot;&amp;gt;&lt;br /&gt;
class NestTry {&lt;br /&gt;
  public static void main(String args[]) {&lt;br /&gt;
    try {&lt;br /&gt;
      int a = args.length;&lt;br /&gt;
      int b = 42 / a;&lt;br /&gt;
      System.out.println(&amp;quot;a = &amp;quot; + a);&lt;br /&gt;
      try {&lt;br /&gt;
        if (a == 1)&lt;br /&gt;
          a = a / (a - a); // division by zero&lt;br /&gt;
        if (a == 2) {&lt;br /&gt;
          int c[] = { 1 };&lt;br /&gt;
          c[42] = 99; // generate an out-of-bounds exception&lt;br /&gt;
        }&lt;br /&gt;
      } catch (ArrayIndexOutOfBoundsException e) {&lt;br /&gt;
        System.out.println(&amp;quot;Array index out-of-bounds: &amp;quot; + e);&lt;br /&gt;
      }&lt;br /&gt;
    } catch (ArithmeticException e) {&lt;br /&gt;
      System.out.println(&amp;quot;Divide by 0: &amp;quot; + e);&lt;br /&gt;
    }&lt;br /&gt;
  }&lt;br /&gt;
}&amp;lt;/source&amp;gt;&lt;br /&gt;
    &lt;br /&gt;
   &lt;br /&gt;
  &amp;lt;!-- end source code --&amp;gt;&lt;br /&gt;
   &lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
==  Catch different Exception types ==&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
   &lt;br /&gt;
  &amp;lt;!-- start source code --&amp;gt;&lt;br /&gt;
   &lt;br /&gt;
    &amp;lt;source lang=&amp;quot;java&amp;quot;&amp;gt;&lt;br /&gt;
class MyException extends Exception {&lt;br /&gt;
  MyException() {&lt;br /&gt;
    super(&amp;quot;My Exception&amp;quot;);&lt;br /&gt;
  }&lt;br /&gt;
}&lt;br /&gt;
class YourException extends Exception {&lt;br /&gt;
  YourException() {&lt;br /&gt;
    super(&amp;quot;Your Exception&amp;quot;);&lt;br /&gt;
  }&lt;br /&gt;
}&lt;br /&gt;
class LostException {&lt;br /&gt;
  public static void main(String[] args) {&lt;br /&gt;
    try {&lt;br /&gt;
      someMethod1();&lt;br /&gt;
    } catch (MyException e) {&lt;br /&gt;
      System.out.println(e.getMessage());&lt;br /&gt;
    } catch (YourException e) {&lt;br /&gt;
      System.out.println(e.getMessage());&lt;br /&gt;
    }&lt;br /&gt;
  }&lt;br /&gt;
  static void someMethod1() throws MyException, YourException {&lt;br /&gt;
    try {&lt;br /&gt;
      someMethod2();&lt;br /&gt;
    } finally {&lt;br /&gt;
      throw new MyException();&lt;br /&gt;
    }&lt;br /&gt;
  }&lt;br /&gt;
  static void someMethod2() throws YourException {&lt;br /&gt;
    throw new YourException();&lt;br /&gt;
  }&lt;br /&gt;
}&amp;lt;/source&amp;gt;&lt;br /&gt;
    &lt;br /&gt;
   &lt;br /&gt;
  &amp;lt;!-- end source code --&amp;gt;&lt;br /&gt;
   &lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
==  catch divide-by-zero error ==&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
   &lt;br /&gt;
  &amp;lt;!-- start source code --&amp;gt;&lt;br /&gt;
   &lt;br /&gt;
    &amp;lt;source lang=&amp;quot;java&amp;quot;&amp;gt;&lt;br /&gt;
public class MainClass {&lt;br /&gt;
  public static void main(String args[]) {&lt;br /&gt;
    int d, a;&lt;br /&gt;
    try {&lt;br /&gt;
      d = 0;&lt;br /&gt;
      a = 42 / d;&lt;br /&gt;
      System.out.println(&amp;quot;This will not be printed.&amp;quot;);&lt;br /&gt;
    } catch (ArithmeticException e) { // &lt;br /&gt;
      System.out.println(&amp;quot;Division by zero.&amp;quot;);&lt;br /&gt;
    }&lt;br /&gt;
    System.out.println(&amp;quot;After catch statement.&amp;quot;);&lt;br /&gt;
  }&lt;br /&gt;
}&amp;lt;/source&amp;gt;&lt;br /&gt;
    &lt;br /&gt;
   &lt;br /&gt;
  &amp;lt;!-- end source code --&amp;gt;&lt;br /&gt;
   &lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
==  Demonstrate multiple catch statements. ==&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
   &lt;br /&gt;
  &amp;lt;!-- start source code --&amp;gt;&lt;br /&gt;
   &lt;br /&gt;
    &amp;lt;source lang=&amp;quot;java&amp;quot;&amp;gt;&lt;br /&gt;
class MultiCatch {&lt;br /&gt;
  public static void main(String args[]) {&lt;br /&gt;
    try {&lt;br /&gt;
      int a = args.length;&lt;br /&gt;
      System.out.println(&amp;quot;a = &amp;quot; + a);&lt;br /&gt;
      int b = 42 / a;&lt;br /&gt;
      int c[] = { 1 };&lt;br /&gt;
      c[42] = 99;&lt;br /&gt;
    } catch (ArithmeticException e) {&lt;br /&gt;
      System.out.println(&amp;quot;Divide by 0: &amp;quot; + e);&lt;br /&gt;
    } catch (ArrayIndexOutOfBoundsException e) {&lt;br /&gt;
      System.out.println(&amp;quot;Array index oob: &amp;quot; + e);&lt;br /&gt;
    }&lt;br /&gt;
    System.out.println(&amp;quot;After try/catch blocks.&amp;quot;);&lt;br /&gt;
  }&lt;br /&gt;
}&amp;lt;/source&amp;gt;&lt;br /&gt;
    &lt;br /&gt;
   &lt;br /&gt;
  &amp;lt;!-- end source code --&amp;gt;&lt;br /&gt;
   &lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
==  Handle an exception and move on. ==&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
   &lt;br /&gt;
  &amp;lt;!-- start source code --&amp;gt;&lt;br /&gt;
   &lt;br /&gt;
    &amp;lt;source lang=&amp;quot;java&amp;quot;&amp;gt;&lt;br /&gt;
import java.util.Random;&lt;br /&gt;
public class MainClass {&lt;br /&gt;
  public static void main(String args[]) {&lt;br /&gt;
    int a = 0, b = 0, c = 0;&lt;br /&gt;
    Random r = new Random();&lt;br /&gt;
    for (int i = 0; i &amp;lt; 32000; i++) {&lt;br /&gt;
      try {&lt;br /&gt;
        b = r.nextInt();&lt;br /&gt;
        c = r.nextInt();&lt;br /&gt;
        a = 12345 / (b / c);&lt;br /&gt;
      } catch (ArithmeticException e) {&lt;br /&gt;
        System.out.println(&amp;quot;Division by zero.&amp;quot;);&lt;br /&gt;
        a = 0; // set a to zero and continue&lt;br /&gt;
      }&lt;br /&gt;
      System.out.println(&amp;quot;a: &amp;quot; + a);&lt;br /&gt;
    }&lt;br /&gt;
  }&lt;br /&gt;
}&amp;lt;/source&amp;gt;&lt;br /&gt;
    &lt;br /&gt;
   &lt;br /&gt;
  &amp;lt;!-- end source code --&amp;gt;&lt;br /&gt;
   &lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
==  Try statements can be implicitly nested via calls to methods ==&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
   &lt;br /&gt;
  &amp;lt;!-- start source code --&amp;gt;&lt;br /&gt;
   &lt;br /&gt;
    &amp;lt;source lang=&amp;quot;java&amp;quot;&amp;gt;&lt;br /&gt;
class MethNestTry {&lt;br /&gt;
  static void nesttry(int a) {&lt;br /&gt;
    try {&lt;br /&gt;
      if (a == 1)&lt;br /&gt;
        a = a / (a - a);&lt;br /&gt;
      if (a == 2) {&lt;br /&gt;
        int c[] = { 1 };&lt;br /&gt;
        c[42] = 99; // generate an out-of-bounds exception&lt;br /&gt;
      }&lt;br /&gt;
    } catch (ArrayIndexOutOfBoundsException e) {&lt;br /&gt;
      System.out.println(&amp;quot;Array index out-of-bounds: &amp;quot; + e);&lt;br /&gt;
    }&lt;br /&gt;
  }&lt;br /&gt;
  public static void main(String args[]) {&lt;br /&gt;
    try {&lt;br /&gt;
      int a = args.length;&lt;br /&gt;
      int b = 42 / a;&lt;br /&gt;
      System.out.println(&amp;quot;a = &amp;quot; + a);&lt;br /&gt;
      nesttry(a);&lt;br /&gt;
    } catch (ArithmeticException e) {&lt;br /&gt;
      System.out.println(&amp;quot;Divide by 0: &amp;quot; + e);&lt;br /&gt;
    }&lt;br /&gt;
  }&lt;br /&gt;
}&amp;lt;/source&amp;gt;&lt;br /&gt;
    &lt;br /&gt;
   &lt;br /&gt;
  &amp;lt;!-- end source code --&amp;gt;&lt;/div&gt;</summary>
			</entry>

	</feed>