Exception Handling

Discussions about design and architecture principles, including native JADE systems and JADE interoperating with other technologies
ConvertFromOldNGs
Posts: 5321
Joined: Wed Aug 05, 2009 5:19 pm

Exception Handling

Postby ConvertFromOldNGs » 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

ConvertFromOldNGs
Posts: 5321
Joined: Wed Aug 05, 2009 5:19 pm

Re: Exception Handling

Postby ConvertFromOldNGs » Fri Aug 07, 2009 11:13 am

by Krull McSkull >> Tue, 12 Jan 1999 5:34:26 GMT

Hi Lloyd,

Lloyd wrote:
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.
One way I have thought of is something like:

<snip> <
flag := true;

epilog
if not flag then
return null;
endif;
return retVal;
end;


This is a reasonable way to do what you require. You can also use: process.isInExceptionState to test whether the process is in exception state in the epilog.
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?


In your example you have defined the size and scale factor for the decimal local var and in the exception case you return null. This seems reasonable, what problem are you attempting to handle exactly?
Also while I'm at it, is it possible to have static methods in Jade?

Sorry, not at the moment, static methods (otherwise known as class methods) are a proposed feature that may be provided in a future release.
And can I dynamically allocate a Decimal at run time?

Do you just want to allocate a decimal, where you don't know the size and scale factor (decimal places) at runtime i.e. you really want a floating-point representation not a fixed-point? If you only need up to 15 digits precision you could use a Real which is double precision and primitive methods for output formatting.

ConvertFromOldNGs
Posts: 5321
Joined: Wed Aug 05, 2009 5:19 pm

Re: Exception Handling

Postby ConvertFromOldNGs » Fri Aug 07, 2009 11:13 am

by Leigh Roberts >> Thu, 14 Jan 1999 0:26:00 GMT
In your example you have defined the size and scale factor for the decimal local var and in the exception case you return null. This seems reasonable, what problem are you attempting to handle exactly?


I'm guessing here but maybe you are trying to limit decimal (or $ values) in some transactions. e.g. 9999 * $123.45 give a huge transaction number you down't want.

If so we handled this with a sledgehammer approach of expecting the return to be a decimal that could deal with 10**12 and then testing to see if it was actually greater than the desired limit.
Also while I'm at it, is it possible to have static methods in Jade?

Sorry, not at the moment, static methods (otherwise known as class methods) are a proposed feature that may be provided in a future release.


This appears to be a feature that will not be included sometime soon. There seems to be those of us who can't understand why it isn't there now and others who can't see the need for it. Why is this so hard to add?

Leigh

ConvertFromOldNGs
Posts: 5321
Joined: Wed Aug 05, 2009 5:19 pm

Re: Exception Handling

Postby ConvertFromOldNGs » Fri Aug 07, 2009 11:13 am

by Krull McSkull >> Thu, 14 Jan 1999 1:09:37 GMT
I'm guessing here but maybe you are trying to limit decimal (or $ values) in some transactions. e.g. 9999 * $123.45 give a huge transaction number you down't want.


Speak for yourself Leigh, I wouldn't turn down that amount in a hurry :-)


Return to “Design and Architecture”

Who is online

Users browsing this forum: No registered users and 14 guests