IT SOLUTIONS
Your full service technology partner! 
-Collapse +Expand
To/From Code
-Collapse +Expand Cross Ref Guide
-Collapse +Expand Members-Only
Sign in to see member-only pages.
   ► KBTo/From GuidesJava  Print This     

Exception Trapping (Java and Delphi Cross Reference Guide)

By Mike Prestwood

Java versus Delphi: A side by side comparison between Java and Delphi.

 
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.

Java:   try/catch/finally
Syntax Example:
try {
  /* Risky code here. */
}
catch (SomeException) {        //one or more.
  /* Recovery here. */
}
finally {                      //0 or one.
  /* Do something. */
}
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;












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


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