Throwing exception with EnableSmartTraps() and try catch

Discussion to talk about software related topics only.
Post Reply
yanb19
Posts: 5
Joined: Thu Dec 17, 2009 10:38 am

Throwing exception with EnableSmartTraps() and try catch

Post by yanb19 »

hi everyone,

I need to know if it is possible to modify or add information with the throwing exception. When the software use EnableSmartTraps() information is send to the RS-232 and you can see information about register and other think... but i would add my own information, like the value of variable x or y etc...if it possible?

and the same time i try to find example to use the try catch to try to find what is cause the throwing exception in the software...but the example i found is all the time in thread for UDP application...

I just try{...my code}catch() { iprintf("value of x %d",x);}... or something like that.

Thanks Yanick.
User avatar
lgitlitz
Posts: 331
Joined: Wed Apr 23, 2008 11:43 am
Location: San Diego, CA
Contact:

Re: Throwing exception with EnableSmartTraps() and try catch

Post by lgitlitz »

When a smarttrap is occurs it means a fatal error has happened. In most cases it also means that it is not possible for the application to proceed any further. Smarttrap is very minimal code that runs in an trap interrupt and attempts to recover stack and system information and then prints it out using a very minimal polling serial driver. This is sort of like if your application caused a blue screen of death on a windows machine. It would not be possible to catch that error and print it out the terminal since the OS and system is already crashed beyond recovery.

You can try to modify the source for smarttrap to print out your variable:
C:\nburn\system\smarttrap.cpp
Stdio will not work here since the OS is not operational. To print you must use the local_out functions such as Local_OutHex and Local_OutString. Depending on the variable it may also trigger another trap and then you will see no info, just a reboot.

You should also use WinAddr2Line to decode the address information in the smarttrap message. Read the smarttrap chapter of the NetBurnerTools documentation:
C:\nburn\docs\NetBurnerPcTools
User avatar
tod
Posts: 587
Joined: Sat Apr 26, 2008 8:27 am
Location: Southern California
Contact:

Re: Throwing exception with EnableSmartTraps() and try catch

Post by tod »

Two things to consider:
1. have found that very often "iprintf" or one of its cousins is the cause of many traps. You can have a sprintf or printf that takes a flag like %f then you change the underlying variable from float to int and forget to change the printf that uses it and you will crash. I have recently been converting everything over to use cout from <iostream> since it is typesafe.

2. I believe exception handling is turned off by default so if you want to try/catch you need to remember to turn it on by clearing the checkbox as shown in the image.
Attachments
ExceptionHandlingOff.png
ExceptionHandlingOff.png (143.2 KiB) Viewed 4188 times
rnixon
Posts: 833
Joined: Thu Apr 24, 2008 3:59 pm

Re: Throwing exception with EnableSmartTraps() and try catch

Post by rnixon »

Tod brings up a good point and solution, but I would also consider just using printf instead of iprintf. Adding all the C++ STL stuff will take up a lot of memory resources. The difference between iprintf and printf is that you save space if you don't link in the floating point library.
yanb19
Posts: 5
Joined: Thu Dec 17, 2009 10:38 am

Re: Throwing exception with EnableSmartTraps() and try catch

Post by yanb19 »

:) Thanks for the reply. it is appreciated. Now I will able to find where is the problem. Thanks again.
Post Reply