When I pasted your code into my app and ran it, it hit the expected
exception, with this stack:

(I wonder if any HTML tags work here? Testing...)

<pre>
Thread [<3> main] (Suspended (exception RuntimeException))
        ActivityThread.performLaunchActivity(ActivityThread$ActivityRecord,
Intent) line: 2496
        ActivityThread.handleLaunchActivity(ActivityThread$ActivityRecord,
Intent) line: 2512
        ActivityThread.access$2200(ActivityThread, ActivityThread
$ActivityRecord, Intent) line: 119
        ActivityThread$H.handleMessage(Message) line: 1863
        ActivityThread$H(Handler).dispatchMessage(Message) line: 99
        Looper.loop() line: 123
        ActivityThread.main(String[]) line: 4363
        Method.invokeNative(Object, Object[], Class, Class[], Class, int,
boolean) line: not available [native method]
        Method.invoke(Object, Object...) line: 521
        ZygoteInit$MethodAndArgsCaller.run() line: 860
        ZygoteInit.main(String[]) line: 618
        NativeStart.main(String[]) line: not available [native method]
</pre>

The Variables view pane listed these variables:
<pre>
this    ActivityThread  (id=830076965832)
<b>e    ArithmeticException  (id=830077313056)  </b>
activity        MyActivity(id=830076998984)
aInfo   ActivityInfo  (id=830076972000)
component       ComponentName  (id=830076971800)
r       ActivityThread$ActivityRecord  (id=830076973192)
customIntent    null
</pre>

The 'e' line was even the one selected for some reason -- coincidence,
I think.
In the subpane at the bottom of the Variables view was this text, as a
result of variable 'e' being selected:

java.lang.ArithmeticException: divide by zero

Switching to the Display view, I entered
e.printStackTrace(), selected it, and did C-Sh-D, and got this:
<pre>
e.printStackTrace()
        Evaluation failed. Reason(s):
                Unable to evaluate the selected expression:

                To perform an evaluation, an expression must be compiled in the
context of a Java project's build path. The current execution context
is not associated with a Java project in the workspace.
Which problem I'd forgotten about. However, continuing, and turning to
the LogCat output, I get the needed information:
</pre>

<pre>
E/AndroidRuntime( 1393): java.lang.RuntimeException: Unable to start
activity ComponentInfo{com.sfsmart.xxx/com.sfsmart.xxx.MyActivity}:
java.
lang.ArithmeticException: divide by zero
E/AndroidRuntime( 1393):        at
android.app.ActivityThread.performLaunchActivity(ActivityThread.java:
2496)
E/AndroidRuntime( 1393):        at
android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:
2512)
E/AndroidRuntime( 1393):        at android.app.ActivityThread.access
$2200(ActivityThread.java:119)
E/AndroidRuntime( 1393):        at android.app.ActivityThread
$H.handleMessage(ActivityThread.java:1863)
E/AndroidRuntime( 1393):        at
android.os.Handler.dispatchMessage(Handler.java:99)
E/AndroidRuntime( 1393):        at android.os.Looper.loop(Looper.java:
123)
E/AndroidRuntime( 1393):        at
android.app.ActivityThread.main(ActivityThread.java:4363)
E/AndroidRuntime( 1393):        at
java.lang.reflect.Method.invokeNative(Native Method)
E/AndroidRuntime( 1393):        at
java.lang.reflect.Method.invoke(Method.java:521)
E/AndroidRuntime( 1393):        at com.android.internal.os.ZygoteInit
$MethodAndArgsCaller.run(ZygoteInit.java:860)
E/AndroidRuntime( 1393):        at
com.android.internal.os.ZygoteInit.main(ZygoteInit.java:618)
E/AndroidRuntime( 1393):        at
dalvik.system.NativeStart.main(Native Method)
<b>E/AndroidRuntime( 1393): Caused by: java.lang.ArithmeticException:
divide by zero</b>
<b>E/AndroidRuntime( 1393):        at
com.sfsmart.xxx.MyActivity.onCreate(MyActivity.java:66)</b>
E/AndroidRuntime( 1393):        at
android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:
1047)
E/AndroidRuntime( 1393):        at
android.app.ActivityThread.performLaunchActivity(ActivityThread.java:
2459)
E/AndroidRuntime( 1393):        ... 11 more
</pre>

You may not be seeing what you want because you stop too soon, before
it's really created the exception. I would have been able to get it to
create the stacktrace for me if I'd captured the exception in my code,
but I did this with zero preparation, except for launching under the
debugger.

If I'd not even done that, I'd still have been able to see the stack
trace from the LogCat output, which would also have given you what you
need to know.

I didn't paste it into this message, but I did look at what was in the
exception, I just clicked on the little triangle to expand. It showed
the message ("Divide by zero"), and also showed that the stacktrace
field hadn't been filled in yet (which I expected).

Going back to your original message, you state:
"  in JDT when an unexpected exception is thrown the call stack
displays the exception class name. but in ADT this doesn't work. "

Um, no, in JDT, when an unexpected exception is thrown, the call stack
normally will NOT display the exception class name, because the
exception class name won't  normally be on the stack. However, the
THREAD may indicate a status (as it does here), of "(suspended
(exception RuntimeException))".

But, I do spot one anomaly here: I have it set to break on
RuntimeException. ArithmeticException is a RuntimeException, but it
didn't break. It didn't break until it tried to rethrow it, further up
the stack. Setting a breakpoint for ArithmeticException explicitly,
DID break at the point of error. When it broke, the stack status was
"(suspended (exception ArithmeticException))". No exception object was
yet available. Hitting the Step Return button twice led to a frame
that had captured it.

This time I capture the exception content for you:
<pre>
        e       ArithmeticException  (id=830077377208)
        cause   ArithmeticException  (id=830077377208)
        detailMessage   "divide by zero" (id=830077377240)
        stackState       (id=830077377320)
        stackTrace      null
</pre>

I hope that helps. Is some aspect of what I did not reproducible in
your environment? Or were you following some other strategy, that hits
some Android-specific snag my personal strategy fortuitously avoids?

On Feb 9, 5:34 pm, RustedInSeattle <guoxiaot...@gmail.com> wrote:
> Thanks Bob,
>
> the problem for me is that even I add a Exception breakpoint, and the
> when the BP is hit, I still cannot get more information from it, there
> is no ex variable I can evaluate. if you want to know what I mean, try
> the following code in onCreate of an Activity class:
>
> public void onCreate(Bundle savedInstanceState) {
>         super.onCreate(savedInstanceState);
>         Log.i(TestActivity.class.toString(),"onCreate called");
>         setContentView(R.layout.main);
>         int b = 0;
>         int a = 1/b; //ArithmeticException
>         System.out.print(a); //just to get rid of warning.
>     }
>
> when the faulty line is hit, debugger stop at the line, but you don't
> know what's in that exception, some exception classes carries more
> information than the name indicates.

-- 
You received this message because you are subscribed to the Google
Groups "Android Developers" group.
To post to this group, send email to android-developers@googlegroups.com
To unsubscribe from this group, send email to
android-developers+unsubscr...@googlegroups.com
For more options, visit this group at
http://groups.google.com/group/android-developers?hl=en

Reply via email to