Handling Try/Catch
Re: Handling Try/Catch
+1
If any of you native English speakers have any suggestions for the above text, please let me know (via PM). Thanks!
-
- User
- Posts: 84
- Joined: Mon Sep 06, 2010 3:05 pm
Re: Handling Try/Catch
+1
(try,catch,finally)
(try,catch,finally)
Re: Handling Try/Catch
With Macro and OnErrorLib
Update 2
Update 2
Code: Select all
;-TOP
Macro Try
OnErrorGoto(?LabelCatch#MacroExpandedCount)
EndMacro
Macro Catch
Goto LabelEndTry#MacroExpandedCount
LabelCatch#MacroExpandedCount:
EndMacro
Macro EndTry
LabelEndTry#MacroExpandedCount:
OnErrorDefault()
EndMacro
;- test
DisableDebugger
MessageRequester("OnError test", "Test 1")
Try
B = 10
A = 10 / B
Catch
A = 0
EndTry
MessageRequester("OnError test", "Test 1: A=" + A)
Try
PokeS(10, "Hello World") ; Cause a #PB_OnError_InvalidMemory error
Catch
MessageRequester("OnError test", "The following error happened: " + ErrorMessage())
EndTry
MessageRequester("OnError test", "Test 2")
Try
B = 0
A = 10 / B
Catch
A = 99
MessageRequester("OnError test", "The following error happened: " + ErrorMessage())
EndTry
MessageRequester("OnError test", "Test 2: A="+ A)
EnableDebugger
Last edited by mk-soft on Sat Apr 29, 2017 1:06 am, edited 1 time in total.
My Projects ThreadToGUI / OOP-BaseClass / EventDesigner V3
PB v3.30 / v5.75 - OS Mac Mini OSX 10.xx - VM Window Pro / Linux Ubuntu
Downloads on my Webspace / OneDrive
PB v3.30 / v5.75 - OS Mac Mini OSX 10.xx - VM Window Pro / Linux Ubuntu
Downloads on my Webspace / OneDrive
Re: Handling Try/Catch
mk-soft wrote:With Macro and OnErrorLib
UpdateCode: Select all
/code][/quote] That is not what we need/want - it doesnt give us any information about the exception...
Re: Handling Try/Catch
To do this, you need to disable the debugger, after which it will not indicate an error in the code.mk-soft wrote:With Macro and OnErrorLib
UpdateCode: Select all
;-TOP Macro Try OnErrorGoto(?LabelCatch#MacroExpandedCount) EndMacro Macro Catch Goto LabelEndTry#MacroExpandedCount LabelCatch#MacroExpandedCount: OnErrorDefault() EndMacro Macro EndTry LabelEndTry#MacroExpandedCount: EndMacro ;- test DisableDebugger MessageRequester("OnError test", "Test 1") Try B = 10 A = 10 / B Catch A = 0 EndTry MessageRequester("OnError test", "Test 1: A=" + A) Try PokeS(10, "Hello World") ; Cause a #PB_OnError_InvalidMemory error Catch MessageRequester("OnError test", "The following error happened: " + ErrorMessage()) EndTry MessageRequester("OnError test", "Test 2") Try B = 0 A = 10 / B Catch A = 99 EndTry MessageRequester("OnError test", "Test 2: A="+ A) EnableDebugger
Re: Handling Try/Catch
Handling Try/Catch
Yes and No
The proper way to code is to always check the availability of a resource before using it
I think Fred probably looked at managing exceptions, but it's likely he did not put it in place because it may take longer to compile and increases the size of the exe
(In My Humble Opinion)
Yes and No
- Yes because it is an easy way to handle errors
- No because it's an easy way to program badly
The proper way to code is to always check the availability of a resource before using it
I think Fred probably looked at managing exceptions, but it's likely he did not put it in place because it may take longer to compile and increases the size of the exe
(In My Humble Opinion)
-
- Addict
- Posts: 2218
- Joined: Mon Jun 02, 2003 9:16 am
- Location: Germany
- Contact:
Re: Handling Try/Catch
The size of the exe will always be increased the more code it contains. A feature is a feature, if you think it bloats your exe too much, you simply don't use it. It is optional and really useful for some projects.Marc56us wrote:I think Fred probably looked at managing exceptions, but it's likely he did not put it in place because it may take longer to compile and increases the size of the exe
Btw should we force handling exceptions like in java or not like in c++? For the first we also need a throws statement at procedures, but I think this cannot be done because you can call procedures via pointer.
bye,
Daniel
Daniel
Re: Handling Try/Catch
+1
Why OpenSource should have a license :: PB-CodeArchiv-Rebirth :: Pleasant-Dark (syntax color scheme) :: RegEx-Engine (compiles RegExes to NFA/DFA)
Manjaro Xfce x64 (Main system) :: Windows 10 Home (VirtualBox) :: Newest PureBasic version