Try (keyword)
From RemObjects Software
The try statement allows you to write code that 'cleans up', even after errors and it has three forms:
- try/finally
- try/except
- try/except/finally
Use the first version to ensure that resource leaks do not occur and to ensure values are always set even after an error:
method TTestForm.OnClick(Sender: Object; ea: EventArgs); begin try fClickCount := fClickCount+1; //fNull.ToString(); //Divide(0); finally fEdit.Text := fClickCount.ToString; end; end;
With the second version, Exceptions may be caught using a try/except block:
method TTestForm.OnClick(Sender: Object; ea: EventArgs); begin try fClickCount := fClickCount+1; //fNull.ToString(); //Divide(0); except on E:Exception do begin MessageBox.Show('Found an error: '+E.Message); end; end; end;
Finally, Oxygene allows you to combine these two blocks, e.g:
method TTestForm.OnClick(Sender: Object; ea: EventArgs); begin try fClickCount := fClickCount+1; //fNull.ToString(); //Divide(0); except on E:Exception do begin MessageBox.Show('Found an error: '+E.Message); end; finally fEdit.Text := fClickCount.ToString; end; end;
See Also
Product: RemObjects Oxygene (formerly known as Chrome)
Current version: 3.0
Previous Versions: 'Joyride' (2.0), 'Floorshow' (1.5), 'Adrenochrome' (1.0)
Glossary — Keywords — Language Features — Platform Features — Samples — Articles — How To — Issues
Categories: Text | Oxygene | Language | Keyword
