Exception handling x++

Dear All,

how i can get the exception object to write the error in customize error log table.

for e.g.

try {

// if any error raise by system the catch block will call

}

catch(Exception::Error)

{

// here how i can know what is the exact error.

}

There is no exception object in X++. But you access messages written to infolog, if it helps. (This approach is used at several places in standard AX.)

If you wanted to log all error messages, Info.add() would be the right place.

Basically we import the journal from external Data base using a job. so i want to log the error in table during journal import.

please let me know what is the best way to error logging ??

Let me show some code first. Feel free to ask if needed.

int         fromEntry;
container   messages;
    
// Simulating infolog messages; remembering where to start logging
info("a");
fromEntry = infolog.line() + 1;
info("b");
info("c");
    
// Get data from infolog - you could save it to database
messages = infolog.copy(fromEntry, infolog.line());
    
// This is how you can show saved messages
infolog.import(messages);

Also consider explicit logging, such as writing to SysExceptionTable.