简体   繁体   中英

Code is not printing stack trace

I have the following code in my android application:

/**
         * Returns a single customer object based on UUID. */
        public static Customer getCustomer(UUID id)
        {
            try
            {
                Cursor cursor = CustomApp.data.db.query("Customer", customerCols,
                        "CustomerId='" + id.toString() + "'", null, null, null, null);
                if (cursor != null)
                    cursor.moveToFirst();
                Customer cust = new Customer(id);

                // Unrelated code here

                if (!cursor.isNull(23))
                    cust.isDeceased = (cursor.getInt(23) > 0); // EXCEPTION

                // More unrelated code here

                return cust;
            }
            catch (Exception ex)
            {
                ex.printStackTrace(); // This line gets skipped
                return null; // Code jumps to here
            }
        }

I'm trying to debug it. Theres an exception on the line cust.isDeceased = (cursor.getInt(23) > 0); ( why I'm getting the exception is another question entirely). When the code reaches that line, it jumps to the catch section. I have put a breakpoint on the line ex.printStackTrace(); but the code skips this line altogether. It just jumps straight to the return null; line, and the stack trace is never printed. Because of this, it is making it very difficult to debug the code as I am having to guess what is wrong. (If you can see something wrong with that code then please do tell me, but it is not the purpose of this question).

I'm sorry for the lack of information/code I have presented, but as I literally have no idea why this would be happening, I do not know what is relevant and what is not. Has anyone encountered this problem before?

Log.e("TAG", "error", ex); try this instead of ex.printStackTrace(); Also try to restart eclipse.

删除try catch子句,logcat会显示详细的异常。

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM