Exception Handling
Posted: Fri Aug 07, 2009 11:13 am
by Lloyd Macrohon >> Wed, 23 Dec 1998 9:14:47 GMT
Hi, I'm new to Jade, and I'm still trying to familarise myself with it.
What is the best way to handle a block of code, where you want all of them executed, if one fails, return some value, else return another value.
e.g.
How can I do something like
(Java or C++)
try {
// do all statements here
// if one fails return null
} catch (Exception ) {
// if something fails
return null;
}
return value;
in Jade?
One way I have thought of is something like:
vars
flag : Boolean;
retVal : String;
begin
flag := false;
on error do myExceptionHandler;
// do these statements
retVal := "Successful";
flag := true;
epilog
if not flag then
return null;
endif;
return retVal;
end;
Which will work, but what about if I return a Decimal (where you have to specify the size, number of decimal places...) and size cannot be determined until runtime?
e.g.
vars
flag : Boolean;
retVal : Decimal[6, 2];
begin
flag := false;
on error do myExceptionHandler;
// do these statements
retVal := 123456.23; // error! retVal not big enough
flag := true;
epilog
if not flag then
return null;
endif;
return retVal;
end;
PS
Can you please CC to my address as well please, since I can't access this newsgroup at work. Also while I'm at it, is it possible to have static methods in Jade? And can I dynamically allocate a Decimal at run time?
TIA,
Lloyd
Hi, I'm new to Jade, and I'm still trying to familarise myself with it.
What is the best way to handle a block of code, where you want all of them executed, if one fails, return some value, else return another value.
e.g.
How can I do something like
(Java or C++)
try {
// do all statements here
// if one fails return null
} catch (Exception ) {
// if something fails
return null;
}
return value;
in Jade?
One way I have thought of is something like:
vars
flag : Boolean;
retVal : String;
begin
flag := false;
on error do myExceptionHandler;
// do these statements
retVal := "Successful";
flag := true;
epilog
if not flag then
return null;
endif;
return retVal;
end;
Which will work, but what about if I return a Decimal (where you have to specify the size, number of decimal places...) and size cannot be determined until runtime?
e.g.
vars
flag : Boolean;
retVal : Decimal[6, 2];
begin
flag := false;
on error do myExceptionHandler;
// do these statements
retVal := 123456.23; // error! retVal not big enough
flag := true;
epilog
if not flag then
return null;
endif;
return retVal;
end;
PS
Can you please CC to my address as well please, since I can't access this newsgroup at work. Also while I'm at it, is it possible to have static methods in Jade? And can I dynamically allocate a Decimal at run time?
TIA,
Lloyd