exception-handling

.NET Core Global exception handler in console application

孤街醉人 提交于 2019-12-10 12:33:26
问题 I'm porting an console application to .NET Core , and I'm trying to replace this line: AppDomain.CurrentDomain.UnhandledException += UnhandledException; After reading this, it seems there is no built-in way to do this. So my question: is the only way to replace this line surrounding my entire code with a try/catch ? By reading this, it seems like there is another way, namely by keep on using System.AppDomain , but I can't seem to find this class/method. My only guess was this library, but it

Is there any easy way to see what exceptions a Kotlin function throws?

a 夏天 提交于 2019-12-10 12:32:38
问题 I mostly understand the potential issues with checked exceptions and why Kotlin omits them. However, the issue I am encountering is I can't find any foolproof way of clearly indicating to the caller what exceptions a function may throw. I have run into the issue countless times in Python where my program will crash after running for months because I didn't realise a function from some library I'm using can raise a particular exception. Although being forced to catch exceptions can be quite

Restful service returns - There was an error checking start element of object of type System.Byte[]. Encountered unexpected character 'ÿ'

一个人想着一个人 提交于 2019-12-10 12:23:06
问题 So I am trying to send an image from the client side to the service. Service definition looks like this (implementation is nothing fancy and It doesn't reach there so excluding that code): [OperationContract] [WebInvoke(Method = "POST", UriTemplate = "Image")] Stream Image(byte [] Image); The calling client looks like this: public static byte[] ImageToByte(Image img) { ImageConverter converter = new ImageConverter(); return (byte[])converter.ConvertTo(img, typeof(byte[])); } string uri =

Exception Translation vs Exception Chaining in Java

若如初见. 提交于 2019-12-10 12:14:50
问题 What is the difference between Exception Translation and Exception Chaining in Java? 回答1: According to Joshua Bloch in Effective Java - Exception Translation Higher layers should catch lower-level exceptions and, in their place, throw exceptions that can be explained in terms of the higher-level abstraction. try { // Use lower-level abstraction to do our bidding ... } catch(LowerLevelException e) { throw new HigherLevelException(...); } Exception Chaining It is special form of exception

Generic exception handling in C++

☆樱花仙子☆ 提交于 2019-12-10 12:08:53
问题 In python you can use: try: #some code except Exception as e: print e And this will automatically catch any exception. Lets say you want to make a simple division in '#some code" ... variable = int(raw_input('Input: ')) result = 50/variable Now, imagine somebody enters 0, or a letter, or even a string... As far as I know, since we used the generic exception catch, all of this will be taken care of and thus the code will jump to the except block, avoiding a crash. In C++, you would have to

How to catch exception?

删除回忆录丶 提交于 2019-12-10 11:52:18
问题 I am trying to call api and check its response, but when ever some wrong value is passed it stops the program. I want to add exception during request and response but not sure how to write in function. This is how i call my REST call public dynamic APICalls(JObject ljson, string endpoints, string method) { var httpReq = (HttpWebRequest)HttprequestObject(endpoints, method); using (var streamWriter = new StreamWriter(httpReq.GetRequestStream())) { streamWriter.Write(ljson); streamWriter.Flush()

Exception handling in method definition or call?

余生长醉 提交于 2019-12-10 11:49:23
问题 I was wondering if there is a right place to handle exceptions. Should I handle it inside my method or should I handle it at the method call? Or does it matter at all? I'm sorry, but I couldn't find anything about this (googling "exception handling scope" didn't returned what I was looking for). Example: // this way... void readFile(string file) { try { /* do my stuff */ } catch(Exception exception) { /* handle exception */ } } int main() { readFile(file); } // or this way? void readFile

Which is better - Throwing an Exception or Checking for errors beforehand

对着背影说爱祢 提交于 2019-12-10 11:46:59
问题 In my server, which is connected to postgresql, should I check if the username already exists in the table by doing "select * ..." and then getting the number of rows in the resultset and i the number of rows is equal to zero, then insert the username? Or just insert the username in the table. If it already exists, then it will throw an error which can then be caught. Note:The username is the primary key Doing which of the above two is better? 回答1: You should do the "try-and-catch exception"

error logging by ELMAH not working in WCF service hosted in IIS with basicHttpBinding

假如想象 提交于 2019-12-10 11:40:41
问题 I followed the steps mentioned in this article http://dotnetslackers.com/articles/aspnet/Getting-ELMAH-to-work-with-WCF-services.aspx to configure WCF service to setup error logging by ELMAH. it works with wsHttpBinding with Visual studio webserver, but when I host it in IIS (5/6) and change the binding to basicHttpBinding, it is not logging the errors. I tried to change the error signalling code to " Elmah.ErrorLog.GetDefault(null).Log(new Error(ex)); " as mentioned at this link ELMAH -

How do appDomain provide Isolation

核能气质少年 提交于 2019-12-10 11:38:49
问题 In my window forms application, I create a Appdomain say sandBox. In this sandbox i excute some code Say TestMethod from TestAppdomain Class. This class is in Test.dll which is not loaded in the current appdomain (Default appdomain). Now while executing TestMethod some exception occurs, then I want the sandbox domain to be unloaded and since AppDOmain provide Isolotion my Default Appdomain shoud not be affected. But As i read over the internet i guess this is not possible.But could some one