Wrapping my code in Try Catch but this message is still being logged to console

-2

This is not a question on what is wrong with my SQL DB and not what is this exception trying to tell me so please stop posting comments on the obvious.

I am wrapping ALL my code in Try {} Catch (Exception){} (and replacing the message with a custom one that is not revealing the table and DB content) but the console is STILL dumping messages out?! How do I hide this detail?

fail: Microsoft.EntityFrameworkCore.Database.Command[20102]
      Failed executing DbCommand (10ms) [Parameters=[], CommandType='Text', CommandTimeout='30']
      SELECT r."mycol1", r."mycol2", r."mycol3"
      FROM "mytable" AS r
      ORDER BY r."mycol1"
Npgsql.PostgresException (0x80004005): 42P01: relation "mytables" does not exist
   at Npgsql.NpgsqlConnector.<>c__DisplayClass161_0.<<ReadMessage>g__ReadMessageLong|0>d.MoveNext()
--- End of stack trace from previous location where exception was thrown ---
   at Npgsql.NpgsqlConnector.<>c__DisplayClass161_0.<<ReadMessage>g__ReadMessageLong|0>d.MoveNext()
--- End of stack trace from previous location where exception was thrown ---
   at Npgsql.NpgsqlDataReader.NextResult(Boolean async, Boolean isConsuming)
   at Npgsql.NpgsqlCommand.ExecuteDbDataReader(CommandBehavior behavior, Boolean async, CancellationToken cancellationToken)
   at Microsoft.EntityFrameworkCore.Storage.Internal.RelationalCommand.ExecuteAsync(IRelationalConnection connection, DbCommandMethod executeMethod, IReadOnlyDictionary`2 parameterValues, CancellationToken cancellationToken)

Does anyone have any idea? :((

c#
logging
.net-core
entity-framework-core
npgsql
asked on Stack Overflow Jul 10, 2019 by Questioner • edited Jul 10, 2019 by Panagiotis Kanavos

1 Answer

0

Are you looking for catching an exception at Application level?

You can do so by putting code inside Application_Error event handler inside global.asax.

**Inside Global.asax**

Public void Application_Error(Object sender, EventArgs e){
   Exception ex = Server.GetLastError();
   Console.WriteLine(ex.Message); 
}

OR

You can do so by putting inside customErrors attribute inside System.web in Web.config

<System.web>
   <customErrors mode="RemoteOnly" defaultRedirect="Errors.aspx">
      <error statusCode="403" redirect="Errors.aspx"/>
      <error statusCode="404" redirect="Errors.aspx"/>
      <error statusCode="500" redirect="Errors.aspx"/>
   </customErrors>
</System.web>
answered on Stack Overflow Jul 10, 2019 by Batgirl

User contributions licensed under CC BY-SA 3.0