News:

MASM32 SDK Description, downloads and other helpful links
MASM32.com New Forum Link
masmforum WebSite

Error Handling

Started by zekyr, August 09, 2011, 03:27:52 AM

Previous topic - Next topic

baltoro

REDSKULL,   
You're probably right.
I often find myself in that phase of writing software where I'm absolutely certain my code is generating errors (and, by that I mean, the code is not doing what I expected). In that case, I want the application to keep running until I terminate it, and I want as much information about its execution as I can get before I rewrite and re-compile.
I think when you are finally past that chaotic phase, you clean up your code and remove all the code blocks you wrote just to get it to work right,...and make it bulletproof,...then you add a more reliable system error checking mechanism.
You probably write pretty clean code. I'm exactly the opposite. I thrash around alot,...
Baltoro

redskull

Quote from: baltoro on August 09, 2011, 11:44:25 PM
when you are finally past that chaotic phase, you clean up your code and remove all the code blocks you wrote just to get it to work right,...and make it bulletproof,...then you add a more reliable system error checking mechanism.

I find that while a good idea in theory, there's never time or money to do this; the squeaky wheel gets the grease, so as long as it works it ships.  The bug doesn't appear until months later when you've forgotten everything and it takes weeks to track down.  If you throw an exception at the first sign of danger (and, conversely, rarely catch anything), then as soon as it breaks you know when, where, and why.  But more importantly, you can't ignore it  :U
Strange women, lying in ponds, distributing swords, is no basis for a system of government

baltoro

Ahhhh,...yes, that makes alot of sense.

Hey,...here's a question,...since all you genuises are reading this,...
This is a very common error,...I've done this in C++ probably millions of times,...and, I would imagine it is even worse in assembly language: dereferencing an invalid pointer. In assembly code it would be dereferencing an invalid address,...one that fails an access check, or, an address to memory that has been released or the data is no longer valid. These things are insidious,...especially in COM, where the application just crashes, and, you have no idea why.
So, the question is: what is the best way to handle an error that you generate when trying to dereference an invalid address ??? Or, worse,...the error you get when trying to write to an invalid address,...and you generate an access violation,...
Here's an interesting post from Raymond Chen's Blog: IsBadXxxPtr Should Really Be Called CrashProgramRandomly

I could never find a great way to deal with this problem. In C++, you set the pointer value to an invalid value, like zero, which can be easily tested. You could do the same thing in assembly language, but, you'd be guaranteed to crash if you didn't first attempt to test the invalid address.
Baltoro

zekyr

Quote from: baltoro on August 09, 2011, 10:18:29 PM
Hilarious ! This is what happens when you ask a bunch of geniuses a simple question,...  :eek
ZEKYR,
There are an almost unlimited number of ways in which to handle an error. For a simple demo application, here at the MASM forum most of the resident geniuses use a simple MessageBox. What amazes me is the number of beginner programmers who never even check return values. Typically, you see the same types of errors over and over.

There really is a lot of nice stuff here :) I write code usually without error checking but I figured I have to grow up sometime! and I wanted to know if there was some compact ways / preferred ways of doing simple error checking stuff; especially since I was having a lot of trouble getting winsocks in icezlion's winsock tutorials working: I was trying to write udp stuff instead of tcp so i wasn't following exactly. I finally got it by the way! just had to do a lot of stepping through code with olly! :)

dedndave

you can use the forum search tool for "SEH" (structured exception handling)
as i understand it, that is how c compilers handle errors - you should feel right at home

jj2007

Quote from: baltoro on August 10, 2011, 01:12:08 AM
dereferencing an invalid address

In development phase, by far the best option is to set Olly as your default debuffer: Options/Debugging/Just-in-time.
So when the error occurs, Olly pops up, you find yourself inside your own code, and Olly shows you exactly what happened.

baltoro

JOCHEN,
Quote from: JOCHENIn development phase, by far the best option is to set Olly as your default debuffer: Options/Debugging/Just-in-time.
So when the error occurs, Olly pops up, you find yourself inside your own code, and Olly shows you exactly what happened.

EXCELLENT,...thanks. I'd never thought of that. Maybe, this will make me a less crappy programmer. :bg
Baltoro