Problem when handler exception

Hi there 

i have problem when handler exception like bellow

i have a function inside have logic call API ,and logic catch exception to write log 

when test for case execute API return code 400 it return screen internal error and seen not througth follow OnException


and OnException follow

And at here have something is unusual,i have set logic just call write log when end OnException follow but by some way it still write log not througth it 

Someone can explain for me why it work.

Thanks

TungNguyen

Hi Tung,

Exception handling in OutSystems are only one level, unless you rethrow an Exception. So if you handle the Exception in an Action, the Action gracefully ends, and doesn't reach the global Exception Handler.

As for getting the "screen internal error", that might be caused by your module not being published, or its consuming module not being published, after you added the Exception handling. Did you try to debug to see what happens?

Kilian Hekhuis wrote:

Hi Tung,

Exception handling in OutSystems are only one level, unless you rethrow an Exception. So if you handle the Exception in an Action, the Action gracefully ends, and doesn't reach the global Exception Handler.

As for getting the "screen internal error", that might be caused by your module not being published, or its consuming module not being published, after you added the Exception handling. Did you try to debug to see what happens?


I tries debug but when debug it througth follow OnException and not return screen internal Error so i don't know what happen for it

about my function it is public

Hi Tung,

If it goes to the OnException when debugging, it should go to the OnException when not debugging. I don't know of situations where Exception handling works while debugging but not while running without the debugger.

The Action being Public has nothing to do with Exception handling, it only determines wheter it's referenceable from another Module.

Kilian Hekhuis wrote:

Hi Tung,

If it goes to the OnException when debugging, it should go to the OnException when not debugging. I don't know of situations where Exception handling works while debugging but not while running without the debugger.

The Action being Public has nothing to do with Exception handling, it only determines wheter it's referenceable from another Module.

As my described above i'm determined it not goes to the OnException because in body of OnException have logic write log but i not found log define after run follow => it not goes to OnException


If the GetFindUser REST API method call triggers an Exception, the Exception goes to the handler you marked with the red square:

There's no logging there, so obviously nothing is logged.

Tung Nguyen wrote:

Kilian Hekhuis wrote:

Hi Tung,

If it goes to the OnException when debugging, it should go to the OnException when not debugging. I don't know of situations where Exception handling works while debugging but not while running without the debugger.

The Action being Public has nothing to do with Exception handling, it only determines wheter it's referenceable from another Module.

As my described above i'm determined it not goes to the OnException because in body of OnException have logic write log but i not found log define after run follow => it not goes to OnException



I have a question how to exception detected by response of API in outsytem (by status code) ?

Hi Tung,

That's honestly a different question, and involves more difficult things like creating an On After Response that detects the error code, adds it to the output, and optionally resets it to 200 to prevent an actual Exception from being triggered (which would prevent the normal flow from continuing).

Kilian Hekhuis wrote:

If the GetFindUser REST API method call triggers an Exception, the Exception goes to the handler you marked with the red square:

There's no logging there, so obviously nothing is logged.

In assign i have a string with log content and will use it as logged


Hi Tung,

No, it will not be logged. The reason for that I have explained above, twice now. Please, try to understand what I'm saying. I can imagine there's a language barrier, but this is important: once the Exception Handler reaches the End, THE GLOBAL EXCEPTION HANDLER WILL NOT(!) BE CALLED!!!!

There. Nothing ever happens with the string you assign. Nothing. Ever. Because the global exception handler will not be called. Exceptions don't bubble up to the Global Exception Handler. So it never ever ever gets logged. The Global Exception Handler is used only when there's an uncaught Exception, i.e. nowhere in the calling stack there's an Exception Handler to catch it.

Also, an Exception Handler has a Property, "Log Error", that has a default "True", that already logs the Exception. So there's really no need to implement your own logging. But if you really must, you need to log it in the local Exception Handler, not the global one.

Kilian Hekhuis wrote:

Hi Tung,

No, it will not be logged. The reason for that I have explained above, twice now. Please, try to understand what I'm saying. I can imagine there's a language barrier, but this is important: once the Exception Handler reaches the End, THE GLOBAL EXCEPTION HANDLER WILL NOT(!) BE CALLED!!!!

There. Nothing ever happens with the string you assign. Nothing. Ever. Because the global exception handler will not be called. Exceptions don't bubble up to the Global Exception Handler. So it never ever ever gets logged. The Global Exception Handler is used only when there's an uncaught Exception, i.e. nowhere in the calling stack there's an Exception Handler to catch it.

Also, an Exception Handler has a Property, "Log Error", that has a default "True", that already logs the Exception. So there's really no need to implement your own logging. But if you really must, you need to log it in the local Exception Handler, not the global one.

Thanks Kilian Hekhuis

I'm understood your comment but in real it not as we discuss because it return internal error

as your explain when once the Exception Handler reaches the End, THE GLOBAL EXCEPTION HANDLER WILL NOT(!) BE CALLED!!!! .Yes i agree with you and also think like that.

But in my app only call internal error screen at OnException so i don't know why it return this screen while not through OnException


Hi Tung,

If the local Exception Handler isn't called, the exception isn't thrown while executing that Action. That's the only reason I can think about. Did you inspect the stack trace of the exception in Service Center to see where it originates?