none
How do I throw an error in a function or register it in the monitor RRS feed

  • Question

  • in C#

    I've tried both of the following:

                throw new Exception("DB down");
                log.Error("DB down");

    Both will do things in the logger, but in the monitor both show success.  How can I tell if my function ran into an error (like above someone shutdown the db I'm checking for example).


    dan

    Friday, September 2, 2016 3:56 AM

Answers

  • When your function fails, you should see that reflected in the "Recent errors count" - I just tried it myself by throwing an exception from a function. The invocation log also shows the failure in red. You're not seeing this? Note that calling log.Error() just writes a log, it won't cause the function to fail.

    Mathew Charles [MSFT]

    Friday, September 2, 2016 5:45 PM

All replies

  • What do you mean by "in the monitor"? Any time your function fails to complete successfully, whether you throw an exception yourself, or whether any of the input/ouput bindings fail before your logic is executed, you should see that failure both in the logs, as well as in the Functions dashboard.

    Mathew Charles [MSFT]

    Friday, September 2, 2016 2:00 PM
  • In the new portal, you can now see Recent errors count

    I suppose maybe I'm asking for a new feature.  I'd like to know how many times my function threw an error caused by a log.Error

    Probably I can write this to some storage area myself and see, but it would be nice if there was something built in.


    dan

    Friday, September 2, 2016 3:15 PM
  • When your function fails, you should see that reflected in the "Recent errors count" - I just tried it myself by throwing an exception from a function. The invocation log also shows the failure in red. You're not seeing this? Note that calling log.Error() just writes a log, it won't cause the function to fail.

    Mathew Charles [MSFT]

    Friday, September 2, 2016 5:45 PM
  • I did   throw new Exception("DB down");

    But I didn't get anything in red, let me try again and I'll show you the logs


    dan

    Friday, September 2, 2016 5:51 PM
  • There can be a slight delay, but it should be working. There's a refresh link as well - you might try hitting that.

    Mathew Charles [MSFT]

    Friday, September 2, 2016 5:53 PM
  • 2016-09-02T17:55:56.852 Try Execption Error:DB down 2016-09-02T17:55:56.852 Try Execption Line #:System.Exception: DB down at Submission#0.Run(TimerInfo myTimer, TraceWriter log) in D:\home\site\wwwroot\UpdateNewZeroDirectPay\run.csx:line 95. 2016-09-02T17:55:56.852 Try Execption Line #:System.Exception: DB down at Submission#0.Run(TimerInfo myTimer, TraceWriter log) in D:\home\site\wwwroot\UpdateNewZeroDirectPay\run.csx:line 95 2016-09-02T17:55:56.852 Function completed (Success, Id=8901cea4-4eed-4528-bb63-c09a3f08ddcc)

    These are my logs from the exceptions I throw.

    But on the monitor page all green checkmarks and 0 recent errors


    dan

    Friday, September 2, 2016 6:00 PM
  • It's working for me fine. I tried in a timer trigger function, and the monitoring tab shows the error. What does your function code look like?

    Mathew Charles [MSFT]

    Friday, September 2, 2016 6:15 PM
  • I'm using c# run.csx, I don't want to put my whole file on there, but here are some parts

    my usings:

    //#r "Oracle.ManagedDataAccess";
    #r "System.Data"
    
    using System;
    using System.Data;
    using System.Data.SqlClient;
    using System.Data.Common;
    using System.Collections.Generic;
    using System.Text;
    using Oracle.ManagedDataAccess.Client;
    using System.Configuration;
    

    Oh, I see.  I had a try{  and was throwing an exception there. That's why  I also had to put the exception in the catch as well.  Thanks for asking me to look at the code again


    dan

    Friday, September 2, 2016 7:56 PM
  • So are you saying you no longer have an issue?

    Mathew Charles [MSFT]

    Saturday, September 3, 2016 3:22 AM
  • yeah, all good.

    dan

    Saturday, September 3, 2016 4:57 AM