Error handling

Hello guys :)

i have a very fast question. As a reminder / notice: i'm new to micro controllers / PICS / Electronics. i'm not to programming.

Let's say i write this piece of code:for (int isz=5; isz>=0; --isz) { int something = somethingElse / isz; } At a point of this loop, a division by 0 will happened. 1) What would be the expected behavior of my Arduino in such case? 2) Is there a general "thing" that happens when any kind of error occurs? 3a) Are try {} catch () {} / throw statements a good idea / available on such memory limited platform? 3b) If 3) = no, why? If 3) = yes, is there any way to get the stack and register states at the time of a crash? 4a) How do you guys handle errors (By errors, i don't mean "expected" errors, but more like "bugs errors") in your programs? 5) Is there a universal way to do it which would be good to learn, and which would be similar to all PICS micro controllers architectures?

Sorry for the load of questions... i'm eager to understand now :D Thanks! Pierre.

The simple way to handle a divide-by-zero is not to allow it to happen. This is a microcontroller - there is no exception mechanism for stuff like this.

PICS

Wash your mouth out!

AWOL: The simple way to handle a divide-by-zero is not to allow it to happen.This is a microcontroller - there is no exception mechanism for stuff like this.

Ha that's what i thought :D Thanks.

AWOL:

PICS

Wash your mouth out!

Sorry. Not having english as my native language + being new to the whole micro controller thing makes me say stuff which probably are horrible. You said that because PIC is a family, i'm sorry i shall have used "micro controllers" instead. i stand corrected, and i'm going to correct my initial posting.

Anyways, what would happened in my Arduino in the case of a division by zero?

what would happened in my Arduino in the case of a division by zero?

Why not try it, and see? Nothing bad will happen, promise.

AWOL:
Why not try it, and see? Nothing bad will happen, promise.

All right, so:

	{
		int			a			= 3;
		int			b			= 0;
		int			c			= a / b;
		Dbg						<< c;
	}
	{
		float		a			= .5;
		float		b			= .0;
		float		c			= a / b;
		Dbg						<< c;
	}

yelds:

Dbg: -1.
Dbg: 4294967295.-1-1.

Odd in the sense the results are incorrect, i would have expected the loop to return or something like that.

i would have expected the loop to return or something like that.

Return to where?

Guess he meant terminate.

AWOL:

i would have expected the loop to return or something like that.

Return to where?

To a previous stack address maybe.

Just another quick question: let's say the Arduino is not wired to anything on it's IO pins. Is there anything which could harm it programmatically?

hickscorp:

AWOL:

i would have expected the loop to return or something like that.

Return to where?

To a previous stack address maybe.

Just another quick question: let's say the Arduino is not wired to anything on it's IO pins. Is there anything which could harm it programmatically?

No. You may get meaningless data fi you try to read something. Other than that it is harmless to leave it as it is. Far as I know.

Is there anything which could harm it programmatically?

If you're really clever, you could probably get it to erase all the program memory, but physical damage? No.

acarb: Guess he meant terminate.

Yes terminate is a more appropriate word for what i had in mind.

No. You may get meaningless data fi you try to read something. Other than that it is harmless to leave it as it is. Far as I know.

Ok, thanks for the answers!

If you're really clever, you could probably get it to erase all the program memory, but physical damage? No.

Hm. Very interesting. i guess i don't have the necessary knowledge yet to do it by itself, but with 2 of them, i think it would resemble to something like that: - Two chips (A and B) linked to each other and acting as programmers to each other when required. - A sends command to B. - B receives the command, and erases A, then uploads some other code to A. - A boots, and executes the code sent by B. It erases B. The only thing left on A and B would be the code required to erase B which would still be on A :D

Pierre.