This page is no longer maintained — Please continue to the home page at www.scala-lang.org

why no stack trace?

4 replies
Russ P.
Joined: 2009-01-31,
User offline. Last seen 1 year 26 weeks ago.
I have a program that reads lines of text from an input file and processes each line as a data record using a method called "processLine". When I run it with this,

                try { processLine(line) }

                catch { case ex: Exception => {
                    println("\nprocessLine failed on line " + lineNum + ":")
                    println(line)
                    }

I see many lines that failed. To determine where it failed, I commented out the "try" block and ran it simply as

                processLine(line)

I expected to get a stack track, but I did not get one. The program just quits early with no indication that anything is wrong. I am logging the input lines, and I can see that it gets to a certain point about halfway through the input file and quits.

The only thing I can think of that might cause this is a "catch" that catches an exception and basically does nothing. I have searched my code for "try" and "catch" and found nothing that seems to explain what I am seeing. Any ideas for what else I should look for of do? Thanks.

Russ P.

--
http://RussP.us
Rich Dougherty 2
Joined: 2009-01-19,
User offline. Last seen 42 years 45 weeks ago.
Re: why no stack trace?
(Forgot to reply to list.)

Hi Russ

Can you provide the commented-out version?

What happens if you replace
  processLine(line)
with
  throw new Exception(line)
?

Rich

On Mon, Jul 19, 2010 at 3:21 PM, Russ Paielli <russ.paielli@gmail.com> wrote:
I have a program that reads lines of text from an input file and processes each line as a data record using a method called "processLine". When I run it with this,

                try { processLine(line) }

                catch { case ex: Exception => {
                    println("\nprocessLine failed on line " + lineNum + ":")
                    println(line)
                    }

I see many lines that failed. To determine where it failed, I commented out the "try" block and ran it simply as

                processLine(line)

I expected to get a stack track, but I did not get one. The program just quits early with no indication that anything is wrong. I am logging the input lines, and I can see that it gets to a certain point about halfway through the input file and quits.

The only thing I can think of that might cause this is a "catch" that catches an exception and basically does nothing. I have searched my code for "try" and "catch" and found nothing that seems to explain what I am seeing. Any ideas for what else I should look for of do? Thanks.

Russ P.

--
http://www.richdougherty.com/
Russ P.
Joined: 2009-01-31,
User offline. Last seen 1 year 26 weeks ago.
Re: why no stack trace?


On Sun, Jul 18, 2010 at 8:48 PM, Rich Dougherty <rich@nil.co.nz> wrote:
(Forgot to reply to list.)

Hi Russ

Can you provide the commented-out version?


I just put /* */ around the whole try/catch block:

                /*
                try { processLine(line) }

                catch { case ex: Exception => {
                    println("\nprocessLine failed on line " + lineNum + ":")
                    println(line)
                    }}
                */

 
What happens if you replace
  processLine(line)
with
  throw new Exception(line)
?


It just stops there and provides a stack track starting with that line.

Russ P.
 
Brian Mosley
Joined: 2010-03-28,
User offline. Last seen 42 years 45 weeks ago.
Re: why no stack trace?

Is there a reason why you can't do something like the following?

try {processLine(line)}
catch {
case ex: Exception => {
println(processLine failed on line " + lineNum + ":")
println(line)
ex.printStackTrace
System.exit(1)
}
}
On 7/18/2010 11:21 PM, Russ Paielli wrote:
> I have a program that reads lines of text from an input file and
> processes each line as a data record using a method called
> "processLine". When I run it with this,
>
> try { processLine(line) }
>
> catch { case ex: Exception => {
> println("\nprocessLine failed on line " + lineNum
> + ":")
> println(line)
> }
>
> I see many lines that failed. To determine where it failed, I
> commented out the "try" block and ran it simply as
>
> processLine(line)
>
> I expected to get a stack track, but I did not get one. The program
> just quits early with no indication that anything is wrong. I am
> logging the input lines, and I can see that it gets to a certain point
> about halfway through the input file and quits.
>
> The only thing I can think of that might cause this is a "catch" that
> catches an exception and basically does nothing. I have searched my
> code for "try" and "catch" and found nothing that seems to explain
> what I am seeing. Any ideas for what else I should look for of do? Thanks.
>
> Russ P.
>

Russ P.
Joined: 2009-01-31,
User offline. Last seen 1 year 26 weeks ago.
Re: why no stack trace?
Thanks. That is exactly what I needed to solve the problem.

I hesitate to say what the problem was, because someone will say "I told you so." I'll go ahead and say it anyway, since others on this list have been helpful. I used "continue" in a block that I forgot to make "continuable." I realize that many Scala developers frown on "continue." The same thing can happen with "break," I believe. They are both set up to avoid a stack trace for efficiency (by using "ControlThrowable"), so if you forget to use "breakable," you will just throw an invisible Exception. I wonder if there is a way to set things up so this mistake is caught at compile time (without too much loss of efficiency).

Russ P.


On Sun, Jul 18, 2010 at 11:03 PM, Brian Mosley <brian_mosley@bellsouth.net> wrote:
Is there a reason why you can't do something like the following?

try {processLine(line)}
catch {
 case ex: Exception => {
   println(processLine failed on line " + lineNum + ":")
   println(line)
   ex.printStackTrace
   System.exit(1)
--
http://RussP.us

Copyright © 2012 École Polytechnique Fédérale de Lausanne (EPFL), Lausanne, Switzerland