exception-handling

a question about exception in c#

怎甘沉沦 提交于 2019-12-12 06:39:30
问题 following is a code snippet: class xxx { public xxx(){} try { throw new Exception(InvalidoperationException); } catch(Exception x) { } catch(InvalidoperationException x) { } } can anyone tell which exception will raise here and what is the reason behind it. 回答1: Wow, lots of problems here. Where to start? That code won't compile. The try-catch block that you've defined is outside of any method, which is not allowed. You need to move it inside of a method. Never throw a method that you intend

Bad argument handling in C/C++

喜欢而已 提交于 2019-12-12 06:22:08
问题 When I run my program like ./program a b c d instead of ./program -i inFile -o outFile it tells me something is wrong with the file opening (which is true )but Expected: "Usage: program -i inputfile -o outputfile\n" Got: "Error: Cannot open file /no/such/file\n" Do you know how should I handle this? Any clue? Also this is part of my code which deals with bad argument handling: if ((s= strrchr( argv[0], '\\')) /* get filename w/o .exe extension */ || (s= strrchr( argv[0], '/'))) s++; else s=

Uncaught exception in a callback from a 3rd party static library

China☆狼群 提交于 2019-12-12 05:42:41
问题 I am compiling my program with a 3rd party library. That library contains an error callback if an error occurs internally. Inside that error callback I am throwing an exception and I have a unit test to verify that when I do something invalid that the exception is thrown. This all works beautifully in Windows, but when I test this in linux (fedora) I am getting an abort from an uncaught exception. I tried wrapping my call directly with a try-catch block but no luck. ( Also, all my code is

ArgumentIndexOutOfBounds Exception string.Length

断了今生、忘了曾经 提交于 2019-12-12 05:39:05
问题 Below is a problem that I have been having the past couple of days. This question is very similar to one I asked yesterday, but when I updated the question no one touched it so I am asking it again in a new question. I am working on a program that takes a large text file, splits it into 2 groups: a and b, and then reads each line of the data. A line of data will look like this: 5/22/2015 12:15:55 AM | Batch 8|429/529|81.10 %|BLV-R|Processed VLZYYL...Checking refundable fares. Traditional

variable might not have been initialized in java

℡╲_俬逩灬. 提交于 2019-12-12 05:28:50
问题 import java.util.Scanner; import java.util.InputMismatchException; public class Demo { public static void main(String [] agrs){ Scanner keyBoard = new Scanner(System.in); int input; do{ System.out.println("[ 1] Case 1."); System.out.println("[ 2] Case 2."); System.out.println("[ 3] Case 3."); System.out.println("[ 0] Case 0."); System.out.print("Your Choice: "); try{ input = keyBoard.nextInt(); } catch(InputMismatchException e){ System.out.println("Error"); } switch (input){ default: System

Exception never reaching the handler in async method (C#) [duplicate]

我与影子孤独终老i 提交于 2019-12-12 04:49:27
问题 This question already has answers here : Catch an exception thrown by an async void method (6 answers) Closed 6 years ago . I have a simplistic structure and I have a hard time understanding why it works (or does not work) how I think it should work. Basically, there are two methods private async void DoStuff() { try { AuthenticationStuff(); }catch(UnauthorizedAccessException){ UI.Display("AMAGAD!"); } } private async void AuthenticationStuff() { var user = GetUser(); if(user == null) throw

Catching exceptions in objective-c

纵然是瞬间 提交于 2019-12-12 04:20:43
问题 Is there some sort of try/catch function in obj-c? I'm trying to load saved files from an array and would like to have some sort of message popping up instead of the app crashing in case the array is empty. Whats the best and optimal way to do this? 回答1: @try { //Code } @catch (id theException) { //Code } @finally { //Code } Or you can test if the array is empty ... 来源: https://stackoverflow.com/questions/6569602/catching-exceptions-in-objective-c

Display server side Exception Message on DataTables.NET

試著忘記壹切 提交于 2019-12-12 04:16:51
问题 I am developing a MVC application which has handles authorization and login information at a base controller class overriding OnActionExecuting event. At AJAX calls when an exception arises I can handle this via attributes and display error messages with on custom model window. My custom attribute is as follows : public class JsonExceptionFilterAttribute : FilterAttribute, IExceptionFilter { public void OnException(ExceptionContext filterContext) { if (filterContext.RequestContext.HttpContext

Using exceptions in Objective-C

前提是你 提交于 2019-12-12 04:07:07
问题 I'm new to Objective-C world. What I have noticed while studying some iOS/Mac apps is that try -catch is rarely used, if used at all. For example in Java it is used almost all the time. Why isn't it so common in Objective-C ? 回答1: There are a lot of SDK methods that take an NSError** parameter and return BOOL . To indicate an error they return false and feed an error back through the error parameter to communicate info. Exceptions are used, but generally for cases in which there is some

Passing exceptions across classes while unit-testing in Python

試著忘記壹切 提交于 2019-12-12 03:32:57
问题 Assume two Python classes, the first of which ( Class 1 ) contains a function ( function_c1 ) that encompasses some statement ( some_statement ), which - if true - returns a customized exception ( MyException ). Further assume that the second class ( Class 2 ) executes the first class and wishes to pass on the customized exception (i.e., return the same exception itself). The following code exemplifies this situation: class Class1: ''' My nifty class 1. ''' def __init__(self): pass def