SaveText with fail-safe?

BlitzMax Forums/BlitzMax Beginners Area/SaveText with fail-safe?

Grisu(Posted 2008) [#1]
Hi!

How can I add a fail-safe to this funtion so that it doesn't crash on errors (File couldn't be written e.g.)?

Thanks Grisu


Perturbatio(Posted 2008) [#2]
try/catch?


Grisu(Posted 2008) [#3]
If I use Savetext on a dir + filename that doesn't exist it simply crashes. The function itself doesn't return true of false like other file commands. So I can't catch an error that way.


grable(Posted 2008) [#4]
So I can't catch an error that way.

Yes you can.
Try
	SaveText( "haha", "c:\..")
Catch e:Object
	Print "oops"
EndTry



Grisu(Posted 2008) [#5]
Oops :) Didn't know of this command.

It catches the first error, but it crashes as soon as you do the same mistake again?

For i:int=0 To 10
Try
	SaveText( "haha", "c:\...")
Catch e:Object
	Print "oops"
EndTry
Next 



Difference(Posted 2008) [#6]
BLR needs to add some error catching to Savetext() ( and maybe Loadtext()?), to make them report some errors like other functions do.

I've reported a similar problem in the past: http://blitzmax.com/Community/posts.php?topic=68176#761629


grable(Posted 2008) [#7]
It catches the first error, but it crashes as soon as you do the same mistake again?

This is a bit weird, it behaves like you would expect in Debug mode with all different types of exceptions.
But in Release mode, it only allows ONE null pointer exception, all the others work as expected.

Might be a bug??