On Fri, 8 Jul 2016 11:34:53 -0700 (PDT)
Raj <rajenderreddykompa...@gmail.com> wrote:

> > > Initially the program giving err driver: bad connection for
> > > rows.Err (). So I added panic with that error to get the stack
> > > trace. 
> >
> > That's very unfortunate as it works right against the debugging by 
> > leading whoever reads your problem statement down the wrong road. 
> >
> > Please don't do that next time: state what's your original problem, 
> > not what you think of it.
> 
>  
> OK. I was trying get the stack trace of the error path and completely 
> messed up. 
> 
> 
> > > for rows.Next() { 
> > >           //stats calculation 
> > > } 
> > > if err := rows.Err(); err != nil { 
> > > panic(err)   *// this is line 498* 
> > > } 
> > > rows.Close() 
> > > 
> > > How can find out the reason for that error? Do I need to search
> > > in the library github.com/alexbrainman/odbc 
> > [...] 
> >
> > Well, instead of asking this question you could just `git grep` the 
> > local clone (what `go get` did for you) of that repository: 
> >   
> >
> Thank you very much for your help.
> Yes, I did dig through the library after posting and ended up having
> same findings.
> It would have helped if there was away to get stack trace of the
> error. 

That's possible by using runtime/debug.PrintStack() at the point where
you've got your error.  But actually temporarily panic()ing is just
okay for such one-off debugguing.

On the other hand, where you think you'd need a stack trace, you might
just reconsider your approach to handling errors.  Often when a
developer thinks they need a stack trace they instead just need _more
context_ of an error.  The PathError type of the "os" standard package
is a good example of providing minimal context for an error related to
operating on filesystem objects.  If you need systematic error handling
which would preserve some context where it would be worth it, you could
use something like [1].

1. 
http://dave.cheney.net/2016/04/27/dont-just-check-errors-handle-them-gracefully

-- 
You received this message because you are subscribed to the Google Groups 
"golang-nuts" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to golang-nuts+unsubscr...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Reply via email to