0

An Azure FunctionApp has 1.5GB of RAM. Sometimes my code goes above this value, and I would like to catch this exception.

Is it possible to do it? The simple try/catch doesn't seem to work.

2 Answers2

0

I do not think there is a separate way to catch this particular type exception, however as best practice you need to use exception handling in your code as given in the docs,

catch(System.Exception ex)
{
    log.LogError(ex, ex.Message);
}
Sajeetharan
  • 216,225
  • 63
  • 350
  • 396
  • The catch block is not triggered. When I run locally I receive in the Console that there is an OutOfMemoryException, but it doesn't go to catch block. Maybe the function app stops immediately when there's no more memory left. – Gheorghe Volosenco Dec 13 '19 at 09:39
0

There are a few exceptions you cannot (guaranteed to be able to) catch.

  1. StackOverflowException - If you run out of the stack, then you cannot possibly execute code that very likely call another function.

  2. OutOfMemoryException - Likely your handling code may need more memory to work.

This answer gives a good explanation

Madushan
  • 6,977
  • 31
  • 79