Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Exception message line number
#1
Is there a way for the exception message to give the line number of the actual offending line of code? Instead, I get the line number of the LogMessage statement...which while helpful is not near as helpful as knowing which line committed the sin.
Reply
#2
Use $Exception.GetLine()...I found it a while back trying out a few variations like GetLn(), etc. It's fun finding those little easter eggs.
It's the early bird that catches the worm, but it's the second mouse that gets the cheese...
Reply
#3
Ya, Dean's a pro at those. Problem is I immediately forget about 'em after this one use...
Reply
#4
beelzerob Wrote:Ya, Dean's a pro at those. Problem is I immediately forget about 'em after this one use...

How about an 'Easter Egg' thread?! :-?
Keith
Reply
#5
Can I pass an exception into a function? I can't find what type it is. Or would $Exception refer to the latest exception, even if referenced in a function where the exception didn't occur?
Reply
#6
It is a Card4. $Exception is the last exception so wherever you were to use $Exception.GetLine() it would be the line of the last exception encountered. I have never tried using it prior to any exceptions being thrown so it would be interesting to see what that gives.

Edit: Since the $Exception magic whatever you call it can only exist within a catch block than you never could use it prior to any exception being thrown...duh....
It's the early bird that catches the worm, but it's the second mouse that gets the cheese...
Reply
#7
Yeah, instead of an Easter Egg thread I would really like to see $Exception fully documented. I realize it is card that is based on an Enum, but I would really like to be able to trace back what type of object the exception occurred in. I recently had a message and couldn't figure out where it was coming from, the ErrorText was so generic, I couldn't make sense of it. I guess line num would've helped too.

I finally fixed the issue through a lot of trial and error. It turned out to be another undocumented error.
Wuench
My Home Theater/Automation Website

[THREAD=5957]BlueGlass CQC Config[/THREAD]
[THREAD=10624]Wuench's CQC Drivers[/THREAD]
Reply
#8
Hmm...so you can't reference $Exception except in a catch block?

I was thinking I could pass the exception into a general LogException function which would output the message to the log, just for cleanliness sake.
Reply
#9
You can do that and that is in fact how I use it. You just need to make the call from within a catch block.

Edit: I get too many of these...Actually the calls I make pass in the $Exception.GetErrorText() and $Exception.GetLine(). Not sure if you could pass in the object itself.
It's the early bird that catches the worm, but it's the second mouse that gets the cheese...
Reply
#10
I wouldn't recommend trying to pass the error object itself. Just get any info out of it you need and pass that. In general, it's best to keep the code in exception handlers as simple as can be to do what needs to be done.
Dean Roddey
Explorans limites defectum
Reply


Possibly Related Threads…
Thread Author Replies Views Last Post
Photo Unhandled GUI Exception simplextech 3 78 01-05-2020, 03:27 PM
Last Post: zra
  Week Number RTV znelbok 1 173 10-22-2019, 06:58 PM
Last Post: Dean Roddey
  Unhandled system exception in GUI Thread Shaky 75 6,914 06-21-2019, 08:10 PM
Last Post: kblagron
Big Grin A Big Thanks on my 1000th Forum Message kblagron 1 778 09-12-2018, 10:35 PM
Last Post: Dean Roddey
  Command Line Switches for installation/upgrade batwater 3 2,026 03-26-2018, 06:24 AM
Last Post: batwater
  Generate Random Number in a Trigger batwater 1 982 12-10-2017, 12:43 PM
Last Post: Dean Roddey
  unclear error message IVB 7 1,993 09-03-2016, 10:32 PM
Last Post: IVB
  Unhandled Exception Scheduled Events zra 8 2,828 06-25-2015, 05:54 PM
Last Post: zra
  Correspond image to number? jkmonroe 1 1,344 02-07-2015, 08:10 PM
Last Post: Dean Roddey
  Command Line Use potts.mike 2 1,709 09-07-2014, 11:08 AM
Last Post: batwater

Forum Jump:


Users browsing this thread: 1 Guest(s)