Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
CODE PROJECT For Those Who Code
  • Home
  • Articles
  • FAQ
Community
  1. Home
  2. Mobile Development
  3. Android
  4. Catch not working, why?

Catch not working, why?

Scheduled Pinned Locked Moved Android
debuggingjavaquestion
5 Posts 2 Posters 8 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • C Offline
    C Offline
    Crazy Joe Devola
    wrote on last edited by
    #1

    When the following code runs, an exception occurs at the setImageResource line. When I debug it, the right after that line the debugger jumps to the finally part, and then it goes into some java code in Runtimeinit.java to a method called private static class UncaughtHandler implements Thread.UncaughtExceptionHandler If I remark the finally section, then the exception is not caught by the catch part? Why isn't the catch part working? Isn't "catch (Exception ex)" supposed to catch any type of exception?

    try {
    ImageView imageV = (ImageView) findViewById(R.id.imageView);

    Log.i(TAG, "before setImageResource");
    imageV.setImageResource(R.drawable.merle);
    

    } catch (Exception ex) {
    Log.e(TAG,ex.getMessage().toString());
    } finally {
    Log.i(TAG,"finally");
    }

    C A 3 Replies Last reply
    0
    • C Crazy Joe Devola

      When the following code runs, an exception occurs at the setImageResource line. When I debug it, the right after that line the debugger jumps to the finally part, and then it goes into some java code in Runtimeinit.java to a method called private static class UncaughtHandler implements Thread.UncaughtExceptionHandler If I remark the finally section, then the exception is not caught by the catch part? Why isn't the catch part working? Isn't "catch (Exception ex)" supposed to catch any type of exception?

      try {
      ImageView imageV = (ImageView) findViewById(R.id.imageView);

      Log.i(TAG, "before setImageResource");
      imageV.setImageResource(R.drawable.merle);
      

      } catch (Exception ex) {
      Log.e(TAG,ex.getMessage().toString());
      } finally {
      Log.i(TAG,"finally");
      }

      C Offline
      C Offline
      Crazy Joe Devola
      wrote on last edited by
      #2

      Solved by adding a catch for Throwable try { ImageView imageV = (ImageView) findViewById(R.id.imageView); Log.i(TAG, "before setImageResource"); imageV.setImageResource(R.drawable.merle); } catch (Exception ex) { Log.e(TAG,ex.getMessage().toString()); } catch (Throwable ex) { Log.e(TAG,ex.getMessage().toString()); } finally { Log.i(TAG,"finally"); }

      1 Reply Last reply
      0
      • C Crazy Joe Devola

        When the following code runs, an exception occurs at the setImageResource line. When I debug it, the right after that line the debugger jumps to the finally part, and then it goes into some java code in Runtimeinit.java to a method called private static class UncaughtHandler implements Thread.UncaughtExceptionHandler If I remark the finally section, then the exception is not caught by the catch part? Why isn't the catch part working? Isn't "catch (Exception ex)" supposed to catch any type of exception?

        try {
        ImageView imageV = (ImageView) findViewById(R.id.imageView);

        Log.i(TAG, "before setImageResource");
        imageV.setImageResource(R.drawable.merle);
        

        } catch (Exception ex) {
        Log.e(TAG,ex.getMessage().toString());
        } finally {
        Log.i(TAG,"finally");
        }

        A Offline
        A Offline
        Awesome Sohel
        wrote on last edited by
        #3

        But why u put this code in try, catch block. Check your layout that present this imageview which id is R.id.imageView.

        1 Reply Last reply
        0
        • C Crazy Joe Devola

          When the following code runs, an exception occurs at the setImageResource line. When I debug it, the right after that line the debugger jumps to the finally part, and then it goes into some java code in Runtimeinit.java to a method called private static class UncaughtHandler implements Thread.UncaughtExceptionHandler If I remark the finally section, then the exception is not caught by the catch part? Why isn't the catch part working? Isn't "catch (Exception ex)" supposed to catch any type of exception?

          try {
          ImageView imageV = (ImageView) findViewById(R.id.imageView);

          Log.i(TAG, "before setImageResource");
          imageV.setImageResource(R.drawable.merle);
          

          } catch (Exception ex) {
          Log.e(TAG,ex.getMessage().toString());
          } finally {
          Log.i(TAG,"finally");
          }

          A Offline
          A Offline
          Awesome Sohel
          wrote on last edited by
          #4

          But why you put this code on try and catch block. Firat see your layout and check that the imageview with id R.id.imageView is contain or not.

          C 1 Reply Last reply
          0
          • A Awesome Sohel

            But why you put this code on try and catch block. Firat see your layout and check that the imageview with id R.id.imageView is contain or not.

            C Offline
            C Offline
            Crazy Joe Devola
            wrote on last edited by
            #5

            It was just a test code. I was more interested in understanding why the try/catch did not work. The imageView was less of a concern in this excercise. Once I was able to trap the error , it turned out to be "not enough memory" because the bitmap I was using was too big.

            1 Reply Last reply
            0
            Reply
            • Reply as topic
            Log in to reply
            • Oldest to Newest
            • Newest to Oldest
            • Most Votes


            • Login

            • Don't have an account? Register

            • Login or register to search.
            • First post
              Last post
            0
            • Categories
            • Recent
            • Tags
            • Popular
            • World
            • Users
            • Groups