exception-handling

Doubt in exception handling and finally block in java

旧时模样 提交于 2019-12-11 04:09:45
问题 Can you tell the idea of how to doing it? Code : public void main(String[] args) { try { //Some Exception throws here } catch(SomeException se) { se.printStackTrace(); } finally { try { //SomeException1 throws here } catch(SomeException1 se1) { se.printStackTrace(); //Control is getting stop in this block itself but i wanna print the below statement } // I need to print this statement whatever exception occurs System.out.println("End Program"); } } 回答1: Just add another finally block public

Catch different Exception types

微笑、不失礼 提交于 2019-12-11 04:04:18
问题 I have a very simple function to check whether an Entity exists in a bundle: public function checkExists($bundle, $val) { try{ $this->em->getRepository($bundle.':'.$val); }catch (MappingException $e){ return false; } return true; } So I have the following cases: Input | Expected | Actual 'AppBundle', 'Company' | true | true 'AppBundle', 'NONEXISTANT' | false | false (MappingException caught) 'NONEXISTANT', 'Company' | false | 500 (ORMException not caught) 'NONEXISTANT', 'NONEXISTANT' | false

C# - “Object reference not set to an instance of an object”

我怕爱的太早我们不能终老 提交于 2019-12-11 03:58:56
问题 I'm currently trying to check if a reference is null before it is used by 'MyMethod' with: if (School.ClassRoom.Pupil.Age != null) { MyMethod(School.ClassRoom.Pupil.Age); } However, I'm still getting the "Object reference not set to an instance of an object" on the first line because not only is the Age null, but also the Pupil and ClassRoom are sometimes null too. I'm getting the same problems using Try, Catch, Finally, since I get the same error in the Try piece of code. I don't want to

Java catching exceptions and subclases

ⅰ亾dé卋堺 提交于 2019-12-11 03:57:37
问题 Hello, In Java if a method like BufferedReader.read() says it can throw an IOException and I try to catch a FileNotFoundException and an IOException in two catch blocks, what catch blocks will be entered if the file doesn't exist? Does it enter only the most specific or both? 回答1: The first coded catch that matches the exception will be entered. Edited to incorporate comment from Azodius For example: try { bufferedReader.read(); } catch (FileNotFoundException e) { // FileNotFoundException

Throwing a New Exception Best Practice [closed]

旧巷老猫 提交于 2019-12-11 03:53:53
问题 It's difficult to tell what is being asked here. This question is ambiguous, vague, incomplete, overly broad, or rhetorical and cannot be reasonably answered in its current form. For help clarifying this question so that it can be reopened, visit the help center. Closed 7 years ago . Is the following good practice and if not what should be done? catch(Exception e) { throw new Exception(e.Message, e); } 回答1: No, this is not good practice if you're throwing another exception of the exact same

How does ASP.NET get line numbers in it's generic error handler

拈花ヽ惹草 提交于 2019-12-11 03:51:14
问题 Everyone is familiar with the default error handler for ASP.NET. The yellow boxes that contain Source Error (5 lines of code where the error happened) and Source File (filename and line number) like so: Source Error: Line 48: public ActionResult TriggerException() Line 49: { Line 50: throw new SystemException("This is a generated exception to test the global error handler."); Line 51: } Line 52: Source File: c:\MyApp\Controllers\TestToolsController.cs Line: 50 I am building a custom error

Should I use a relevant built-in unchecked exception where the theory prescribes using a checked one?

末鹿安然 提交于 2019-12-11 03:49:02
问题 There are quite a few posts on SO about the "checked vs unchecked exception" topic. This answer is probably the most well-rounded and informative. Yet I'm still conflicted to follow the logic presented there, and there's a reason for that. I'm building a wrapper API around a set of services similar to each other. There are, however, minor differences between them (or a possibility of such in the future), so that certain functions (of secondary and shortcut nature) may be supported by some

NSUserDefaults saves details sometimes and doesn't someother times

不羁的心 提交于 2019-12-11 03:43:54
问题 I use NSUserDefaults to save some data locally. But the problem is it doesn't save the data all the times. For instance: While an app is crashing I save the execption related informations using NSUserDefaults - (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions { NSSetUncaughtExceptionHandler(&onUncaughtException); } void onUncaughtException(NSException* exception) { //save exception related details using NSuserdefaults } 回答1: The

__try and __exception portability

早过忘川 提交于 2019-12-11 03:42:14
问题 Hello and excuse me again I am reading "Detecting Multiprocessor Topology in IA-32 Architecture" from Intel. I was recoding the example. However I read this sentences __try and __except in the code. I found MSDN Microsoft web page some information but I am using gcc compiler/linker are __try and __except valid sentences in gcc? are __try and __except portable sentences on *nux environments? do exist a better mode than __try and __except sentences for exception handling in C? Thanks in advance

Openejb rest integration tests with exception mappers

℡╲_俬逩灬. 提交于 2019-12-11 03:34:13
问题 I'm writing some integration tests towards my jax-rs service where I have a set of exception mappers. So, when performing a given request I expect a certain response code based on the exception mapper. The problem is that I cannot get the exception mappers to be invoked when running in this environment. My service which should throw a logicalexception in my test: @Stateless @Path("/baseCustomer") public class BaseCustomerService { @EJB //this one gets mocked in the unittest private