[Implemented] More sophisticated error trapping

Got an idea for enhancing PureBasic? New command(s) you'd like to see?
BackupUser
PureBasic Guru
PureBasic Guru
Posts: 16777133
Joined: Tue Apr 22, 2003 7:42 pm

Post by BackupUser »

Restored from previous forum. Originally posted by PB.

Tinman was right: they had a start-up app that added data to all window titles.
Obviously Tinman has experienced this before, to have thought of it, but I hadn't,
and was stumped at the time for days. :)

> But let me ask you: did your program fall over?

No, it just didn't move the calc -- my app had error-trapping not to die if it
couldn't find the window. It was a good learning experience for me, as I had
never seen an app before that changed ALL window titles on a system-wide basis.

Just goes to show you can never be 100% sure how a user's system will operate.
BackupUser
PureBasic Guru
PureBasic Guru
Posts: 16777133
Joined: Tue Apr 22, 2003 7:42 pm

Post by BackupUser »

Restored from previous forum. Originally posted by tinman.
Originally posted by Amiga5k

Wow Tinman, you must be the brainiac of the computer programming world if you think you can predict EVERY possible thing the user is going to try (intentionally or otherwise):
But it should have been logical to think it might be entered.
The part of my quote you highlighted isn't rocket science. You're working with strings, it's logical to think that you can get ASCII or Unicode, especially in Windows, especially on non-English systems. If you think that makes me some kind of brainiac then thats great.

Consider an application you write. The user can only realistically work within the confines of the gadgets, processes and things that your application provides. Yes, there will be a degree of system interaction which they can do to break your program, such as deleting DLLs, but you'll have thought about them and included checks for them.
So Ricardo's supposed to test his program on every version of Windows in the world (There are dozens, BTW) for every eventuality?
No and I didn't say he should.
Do you think you can produce a program of any appreciable length that can't be crashed?
What do you mean by appreciable length and what means can I use to get that length?

Code: Select all

End
DataSection
IncludeBinary "some_50_meg_file.bin"
EndDataSection
It's an appreciable length but I cannot say that it can't be crashed because I have no control over the code that PureBasic uses as startup, shutdown or the End keyword.

On different systems, using different languages then I may say yes (and yes, that is without exception handling).
You'd be the first ever, my friend! In Ricardo's case, an exception handler would have 'caught' the potential crash and allowed his program to report the error to the user, save information first, etc.
How can you know if the error would have been caught by the exception handler? How do you know ricardos program could have recovered? As plouf said, how do you police the exception handler?
As far as slowing the program down, depending on how the exception handling is done, sometimes extra code is inserted in the executable loop which will slow down the program. Ever notice that PB runs slower in Debug mode?
If you have done your own error checking then a lot of the PureBasic debug checking is not needed. My point there was that exception handling should not necessarily be slower than normal error checking, because you would be performing the same checks at each stage.
I think you're confusing error checking with exception handling. They're not the same thing. Error checking is something we should all be doing (i.e. Check to see if a file exists before you try to load it, etc). Exception handling is the next step up from that.
So what is exception handling other than a different means of reporting a problem that would normally be found by error checking? What is "the next step up"? If I am misunderstanding it then please explain why and how exceptions are so much better than error checking.

(Edit: fixed missing /quote which mangled the message)

--
I used to be a nihilist but I don't believe in that any more.
(Win98first ed. + all updates, PB3.62, external editor)
BackupUser
PureBasic Guru
PureBasic Guru
Posts: 16777133
Joined: Tue Apr 22, 2003 7:42 pm

Post by BackupUser »

Restored from previous forum. Originally posted by ricardo.

Tinman,

Fred is a very good programer and with every version of PureBasic we find some bugs.
Ok, we are all trying to be good programmers and so we report bugs and understand all.

The average user don't. If they found a bug want a refund. They dont understand and dont care about fixing bugs.

Many of my users cant uderstand that the .cda file its not an wav file... in fact they dont know the difference betwen wav and mp3.

In fact many of them dosent know how to use their own computer much. You may laught if you read some emails that i receive every day asking the more incredible questions.
And its logic, i develop the software. They are not idiots, are just users.
As i dont know nothing about building a house or repairing my vehicule or about medicine.

Then, we must need to get every exception and handle in some way. The user cant help when having a trouble, they dont want to find crashes, but they contribute to crashes with an extraordinary capacilitie to generate troubles

Any software directed not to programmers or specialized users but to the general users (i have users 73 years old!) must be 'Idiot Proof' and some error handling like VB has could be usefull to acomplish that.



Best Regards

Ricardo

Dont cry for me Argentina...
BackupUser
PureBasic Guru
PureBasic Guru
Posts: 16777133
Joined: Tue Apr 22, 2003 7:42 pm

Post by BackupUser »

Restored from previous forum. Originally posted by Amiga5k.

Sorry, Tinman, for coming at you with both guns firing :)... It just blew my mind that someone would argue against this sort of error control. Here's an example that could not be paractically caught by conventional error checking means: A user has a file on a hot-swappable HD, meaning it can be removed at any time and replaced by another one. Your program is reading a file from here when the user thinks, "Oh wait! It's on this other disk!" and pulls that one out in the middle of a write operation.
Now, you could check for the existance of the file before every single write, but I dare say that the file access times would be increased by a very large factor. And without this, the program would definitely crash when they removed the disk (unless PB has some inherent file-error catching code we don't see - which is possible).
Anyway, this is just one way that exception handling can come in handy, especially when you're dealing with things outside of the control of your program, such as removable hard drives.

Russell

***Commodore 64 - Over one million cycles per second, 16 vibrant colors, 3 incredible audio channels and 38,911 Basic Bytes Free! Who could ask for anything more?***
BackupUser
PureBasic Guru
PureBasic Guru
Posts: 16777133
Joined: Tue Apr 22, 2003 7:42 pm

Post by BackupUser »

Restored from previous forum. Originally posted by TheBeck.
Sorry, Tinman, for coming at you with both guns firing ... It just blew my mind that someone would argue against this sort of error control. Here's an example that could not be paractically caught by conventional error checking means: A user has a file on a hot-swappable HD, meaning it can be removed at any time and replaced by another one. Your program is reading a file from here when the user thinks, "Oh wait! It's on this other disk!" and pulls that one out in the middle of a write operation.
Now, you could check for the existance of the file before every single write, but I dare say that the file access times would be increased by a very large factor. And without this, the program would definitely crash when they removed the disk (unless PB has some inherent file-error catching code we don't see - which is possible).
Anyway, this is just one way that exception handling can come in handy, especially when you're dealing with things outside of the control of your program, such as removable hard drives.

Russell
This is the job for the operating system and Windows does a good job of it so this should not be a problem. The OS should just throw up an error window asking for you to insert the correct disk.

I think PureBasic's error handling is sweet and simple, the way it should be.
BackupUser
PureBasic Guru
PureBasic Guru
Posts: 16777133
Joined: Tue Apr 22, 2003 7:42 pm

Post by BackupUser »

Restored from previous forum. Originally posted by ricardo.

We dont need to go to extremes.

If somebody dont use any way to prevent errors, it his fault.
Just like if the coder uses wrong the memory commands or any other. Its not a PB problem but coder problem.
The PB language could offer, however, some commands to catch exceptions and i think that everybody is agree with this here.

The wise usage of them as any other command depends on the coder.

Best Regards

Ricardo

Dont cry for me Argentina...
BackupUser
PureBasic Guru
PureBasic Guru
Posts: 16777133
Joined: Tue Apr 22, 2003 7:42 pm

Post by BackupUser »

Restored from previous forum. Originally posted by Amiga5k.

Exactly, Ricardo. Also, there must be SOME reason that many respectable languages out there include these types of commands (Java, Python, PowerBasic...even Visual Basic!). And I dare say that your average Python programmer is not a "weekend programmer", and is used to checking for the usual error types. :)

I know that removing a removable disk during a write operation will crash the system because I've done it...accidentally . Try/Catch/Finally would have saved me there. Granted, I'm not going to attempt to program anything like an operating system anytime soon, so I can wait for these types of commands to appear in a future version of PB (and I believe they will, eventually).

Russell

***Commodore 64 - Over one million cycles per second, 16 vibrant colors, 3 incredible audio channels and 38,911 Basic Bytes Free! Who could ask for anything more?***
Post Reply