[lnkForumImage]
TotalShareware - Download Free Software

Confronta i prezzi di migliaia di prodotti.
Asp Forum
 Home | Login | Register | Search 


 

Forums >

microsoft.public.axapta.programming

How to catch exception's description ?

arno

11/14/2005 11:56:00 AM

Hi,

How to catch the description's exception in the catch block ?

try
{
// statements
}
catch (exception::error)
{
// print ("the error is"+ exception.description") ????

}

Thanks,
arno


4 Answers

Mike Frank

11/14/2005 3:05:00 PM

0

As a starting point you have to understand, that Axapta has no "real" Exceptions. The notion of an
Exception (class) is not known in Axapta.
With the standard handling all "exception" messages are written to the infolog. That's where you can
get those messages from and that's where you have to delete them, if you want to replace the
standard messages with your own.

Below is an example how you could do that. Be aware, that the way the infolog contents are read is a
very simplistic approach, that will not work in a real world scenario. All standard checking
procedures will put some warning messages into the infolog and then a final line, saying that the
process was aborted. So you would have to consider all lines. The infolog container holds two
entries for every infolog line (one with an enum for the level (info, warning, error) and another
with the actual message. The message line itself will contain possible prefixes. This you could
process with the help of the SysInfologItem class.

All depends on what you want to do. The best way is to run with standard behaviour wherever it is
possible.

int logpoint;
container infologCon;
;
info("Before");

try
{
logpoint = infolog.line();

throw error("Forced error");
}
catch (Exception::Error)
{
// get the contents of the infolog
infologCon = infolog.copy(logpoint + 1, infolog.line());

// delete handled messages from infolog
infolog.cut(logpoint + 1, infolog.line());

// put your own message in
info(strfmt("The following error was found: %1", conlen(infologCon) >= 2 ?
strrem(conpeek(infologCon, 2), '\t') : ''));
}

arno

11/14/2005 5:40:00 PM

0

Hi Mike,

Thanks for your answer.
The idea is to centralize exception in a global repository. (an axapta table
with a custom app to read them)
The advantages are to have a better view of the application's problems, and
to not wait to be notified before correcting a bug.

So, I need the description of the 'exception' to log it ...

Is there an infologLine for all the exceptions ?
For example, If I compute a divide by zero operation, there's nothing in the
Infolog ...

What about exception thrown by classes that are executed on the server (AOS)
?

Thanks,

arno

"Mike Frank" <mifra@nospam.de> wrote in message
news:%23%23CnIyS6FHA.3636@TK2MSFTNGP09.phx.gbl...
> As a starting point you have to understand, that Axapta has no "real"
> Exceptions. The notion of an Exception (class) is not known in Axapta.
> With the standard handling all "exception" messages are written to the
> infolog. That's where you can get those messages from and that's where you
> have to delete them, if you want to replace the standard messages with
> your own.
>
> Below is an example how you could do that. Be aware, that the way the
> infolog contents are read is a very simplistic approach, that will not
> work in a real world scenario. All standard checking procedures will put
> some warning messages into the infolog and then a final line, saying that
> the process was aborted. So you would have to consider all lines. The
> infolog container holds two entries for every infolog line (one with an
> enum for the level (info, warning, error) and another with the actual
> message. The message line itself will contain possible prefixes. This you
> could process with the help of the SysInfologItem class.
>
> All depends on what you want to do. The best way is to run with standard
> behaviour wherever it is possible.
>
> int logpoint;
> container infologCon;
> ;
> info("Before");
>
> try
> {
> logpoint = infolog.line();
>
> throw error("Forced error");
> }
> catch (Exception::Error)
> {
> // get the contents of the infolog
> infologCon = infolog.copy(logpoint + 1, infolog.line());
>
> // delete handled messages from infolog
> infolog.cut(logpoint + 1, infolog.line());
>
> // put your own message in
> info(strfmt("The following error was found: %1",
> conlen(infologCon) >= 2 ? strrem(conpeek(infologCon, 2), '\t') : ''));
> }
>


HS

11/15/2005 9:57:00 PM

0

info(conpeek(infolog.copy(infolog.numFrom(1,Exception::Error),infolog.num(Exception::Error)),2));

HS
; )
"arno" wrote:

> Hi,
>
> How to catch the description's exception in the catch block ?
>
> try
> {
> // statements
> }
> catch (exception::error)
> {
> // print ("the error is"+ exception.description") ????
>
> }
>
> Thanks,
> arno
>
>
>

Mike Frank

11/17/2005 11:08:00 AM

0

> Is there an infologLine for all the exceptions ?
There should be, if the exception was thrown with throw error(MessageTxt).
The problem is, that there could be even several lines for one exception.

Consider the following code from ProdUpdStartUp.run()

if (! this.validate())
throw error("@SYS18447");

Boolean validate()
{
if (prodTable.qtyStUp + prodParmStartUp.startUpQty < 0)
return checkFailed("@SYS22688");

return true;
}

You would have the checkFailed (level warning) and the abort message (level error) in two infolog
lines.

You could use the prefixes to determine which messages belong together, but this depends of course,
if everyone and in everyplace is coding up to the standard practices.

A starting point to log all exceptions could be the Info.add method, where you could collect all
messages depending on the exception type. This method is called by the Global::error (warning, info)
messages and also by kernel messages, that want to report an error.

> For example, If I compute a divide by zero operation, there's nothing in the
> Infolog ...

That's a sad story, a divide by zero is not really catched in Axapta

Mike