4

When writing an Azure Function in compiled C#/F#, what's the cleanest way to signal to the Function runtime that the function failed?

I know that throwing an exception will result in a failure, but I'd prefer to handle those internally. I've also noticed that when when the function writes to log.Error the execution is still considered successful.

Is throwing an exception the only way to signal a failure, or is there a better practice?

John Hoerr
  • 7,955
  • 2
  • 30
  • 40

1 Answers1

6

Yes, throwing an exception is how you signal a failure. Even if you log errors inside of your function, the function host doesn't take that into consideration when determining success/failure.

brettsam
  • 2,702
  • 1
  • 15
  • 24
  • Just make sure you create your own Exception type, because things are going to look very confusing when you'll look at telemetry in Application Insights later on mashed together with all kinds of other (runtime?) exceptions. Expanding the Stack Trace ruins the bird's eye view... that could be a quote look at it :) – evilSnobu Sep 29 '17 at 00:08