Do or Die

Share your advanced PureBasic knowledge/code with the community.
User avatar
GedB
Addict
Addict
Posts: 1313
Joined: Fri May 16, 2003 3:47 pm
Location: England
Contact:

Post by GedB »

Rings,

That is pretty neat.

However, what I'm really after is a way of tucking away the testing code when creating windows and the like.

Kale's HandleError is almost there, but it is intrusive because HandleError becomes the first item on the line. You have to scan over for the OpenWindow.

The advantage of Do or Die is that the exception handling can easily be ignored.
Kale
PureBasic Expert
PureBasic Expert
Posts: 3000
Joined: Fri Apr 25, 2003 6:03 pm
Location: Lincoln, UK
Contact:

Post by Kale »

The advantage of Do or Die is that the exception handling can easily be ignored.
Thats exactly why i like your method :)
Kale's HandleError is almost there...
Not mine, i think i 'borrowed' the idea from the IDE source! Beriko? :)
--Kale

Image
User avatar
Psychophanta
Always Here
Always Here
Posts: 5153
Joined: Wed Jun 11, 2003 9:33 pm
Location: Anare
Contact:

Post by Psychophanta »

This great feature still works fine in 4.0 :!: :D :idea: :wink: 8) :) :o

Code: Select all

Procedure error_end(message.s,message2.s)
  MessageRequester(message.s,message2.s,#PB_MessageRequester_Ok):End
EndProcedure
hWnd.l=OpenWindow(0,0,0,80,40,"a window",#PB_Window_ScreenCentered|#PB_Window_SystemMenu)
hWnd.l Or error_end("Error","Something fails: i can't open window")
Delay(1000)
Please Fred keep it working :wink:
http://www.zeitgeistmovie.com

while (world==business) world+=mafia;
User avatar
Joakim Christiansen
Addict
Addict
Posts: 2452
Joined: Wed Dec 22, 2004 4:12 pm
Location: Norway
Contact:

Post by Joakim Christiansen »

I like the idea, do this or do that, never seen it before that simple! :D
SFSxOI
Addict
Addict
Posts: 2970
Joined: Sat Dec 31, 2005 5:24 pm
Location: Where ya would never look.....

Post by SFSxOI »

I'm still learning this stuff and I don't understand why its not safe.

Why is it not safe?

I kinda like it, even tho I don't understand why its not safe.

Fred wrote:This is not safe, I suggest to always put an 'IF' before, as an expression requiers a keyword.
User avatar
Psychophanta
Always Here
Always Here
Posts: 5153
Joined: Wed Jun 11, 2003 9:33 pm
Location: Anare
Contact:

Post by Psychophanta »

SFSxOI wrote:I'm still learning this stuff and I don't understand why its not safe.
Same here.
Please Fred, could you explain a little.
http://www.zeitgeistmovie.com

while (world==business) world+=mafia;
User avatar
GedB
Addict
Addict
Posts: 1313
Joined: Fri May 16, 2003 3:47 pm
Location: England
Contact:

Post by GedB »

Officially all expressions in PB should be accompanied by a keyword.

That means that this is an illegal expression. The fact that it works could be viewed as a bug.
josku_x
Addict
Addict
Posts: 997
Joined: Sat Sep 24, 2005 2:08 pm

Post by josku_x »

correction: as a GOOD bug. :wink:

I think a command like this that would be 'safe' should be added to the next version of PB, because with this you can save time and source-size:

The SAFE method Fred recommended to use:

Code: Select all

Procedure Die(Message$)
 MessageRequester("Error", Message$, #MB_ICONERROR)
 End
EndProcedure
Procedure ReturnValue(Value)
 ProcedureReturn Value
EndProcedure
If ReturnValue(#False)
Else
 Die("ReturnValue returned #false")
EndIf
The method that is COOL:

Code: Select all

Procedure Die(Message$)
 MessageRequester("Error", Message$, #MB_ICONERROR)
 End
EndProcedure
Procedure ReturnValue(Value)
 ProcedureReturn Value
EndProcedure
ReturnValue(#False) Or Die("ReturnValue returned #false")
:?:
User avatar
Joakim Christiansen
Addict
Addict
Posts: 2452
Joined: Wed Dec 22, 2004 4:12 pm
Location: Norway
Contact:

Post by Joakim Christiansen »

Indeed :D
Fred, pleas let us have this! :D And make it safe :D
josku_x
Addict
Addict
Posts: 997
Joined: Sat Sep 24, 2005 2:08 pm

Post by josku_x »

In PHP, you can use many keywords without having the IF or another keyword before it. For example, you can do this in PHP:

Code: Select all

$Value=$This AND $That
User avatar
Psychophanta
Always Here
Always Here
Posts: 5153
Joined: Wed Jun 11, 2003 9:33 pm
Location: Anare
Contact:

Post by Psychophanta »

Joakim Christiansen wrote:Indeed :D
Fred, pleas let us have this! :D And make it safe :D
Besides, the legibility is great! Nothig to envy to If...EndIf :)
http://www.zeitgeistmovie.com

while (world==business) world+=mafia;
Post Reply