IT SOLUTIONS
Your full service technology partner! 
+Expand
   ► KBTo/From GuidesDelphi  Print This     

Exception Trapping (Delphi and VB.Net Cross Reference Guide)

By Mike Prestwood

Delphi versus VB.Net: A side by side comparison between Delphi and VB.Net.

 
Statements
 

Common statements such as if statements, loops, etc.

Exception Trapping

[Other Languages] 

Languages Focus

A common usage of exception handling is to obtain and use resources in a "try-it" block, deal with any exceptions in an "exceptions" block, and release the resources in some kind of "final" block which executes whether or not any exceptions are trapped.

Delphi:   try..except, try..finally

Use a try..except..end block to trap and process errors.

Delphi also offers a try...finally where code will execute in the finally section no matter what. It's common to put a try..except inside a try..finally.

Syntax Example:
var
y : Double;
begin
try
y := 0;
y := (1/y);
ShowMessage(FloatToStr(y));
except
ShowMessage('You cannot divide by zero.');
end;
end;
VB.Net:   Try...Catch...Finally

VB.Net uses a try...catch...finally statement to trap for errors.

Try
Catch
Finally
End Try
Syntax Example:
Try
Dim y As Integer = 0
y = 1 / y
Catch
MessageBox.Show("you cannot divide by zero")

End Try












Sales Website: www.prestwood.com Or visit our legacy sales site: 
legacy.prestwood.com


©1995-2025 Prestwood IT Solutions.   [Security & Privacy]