exception-handling

What is the point of finally in a try catch/except finally statement

半腔热情 提交于 2019-12-31 08:14:29
问题 I have used try-catch/except-finally variants in many languages for years, today someone asked me what is the point of finally and I couldn't answer. Basically why would you put a statement in finally instead of just putting it after the whole try-catch block? Or in other words is there a difference between the following blocks of code: try{ //a} catch {//b} finally {//c} try{//a} catch{//b} //c EDIT: PEOPLE, I know what finally does, I have been using it for ages, but my question is in the

Exception not cuaght with Entity Manager

て烟熏妆下的殇ゞ 提交于 2019-12-31 06:38:31
问题 I have an Entity Manager in my EJB @PersistenceContext(unitName = "cnsbEntities") private EntityManager em; I populate an object and then I commit it in my DB, but if I have an exception, for duplicate ID, I can't catch it and I don't know why. try{ em.merge(boelLog); } catch (Exception e){ System.out.println("Generic Exception"); } 回答1: JPA uses transactions to send entity modifications to the database. You can specify those transactions manually through Bean Managed Transactions (BMT) or

Shutdown exception handling for Win32/C++

时光毁灭记忆、已成空白 提交于 2019-12-31 04:36:09
问题 I have a process that handles exceptions great. It calls: _set_se_translator(exception_trans_func); SetUnhandledExceptionFilter(UnhandledExceptionFilterHandler); _set_purecall_handler(purecallHandler); set_terminate(terminateHandler); set_unexpected(unexpectedHandler); _set_invalid_parameter_handler(InvalidParameterHandler); atexit(exitHandler); //ignored during an expected exit _onexit(onexitHandler); //ignored during an expected exit Anytime an exception happens, one of the handlers is

How to handle errors in my CustomAutorize attribute in asp.net 3.0 Application

白昼怎懂夜的黑 提交于 2019-12-31 04:32:07
问题 I am working on an asp.net MVC 3.0 Application. I am using using my own CustomRoleProvider and CustomErrorHandler by overriding default attributes. Every thing is working fine. But ,the problem is with the exception handling. While testing the application , tester has given invalid DB connection to test. The result is , Custom Error Handler is not rendering Error View , instead it is routing the original path For ex: I am running my application as Home/Index It is first hitting Custom Role

java.lang.OutOfMemoryError: OutOfMemoryError thrown while trying to throw OutOfMemoryError; no stack trace available

你说的曾经没有我的故事 提交于 2019-12-31 03:05:19
问题 I am trying to compare values of lat long provided by user with values of lat long from database. If they are in 15 km radius of each other textview should be changed. But i am facing following error, My database contains value source lat = 19.218418 source long = 73.08661 Des lat = 18.9766017 des long = 72.8326658. and values provided by user are soure lat = 19.2213935 source long= 73.081532 des lat = 18.9632933 des long = 72.8324848. E/AndroidRuntime: FATAL EXCEPTION: main Process: com

java.lang.OutOfMemoryError: OutOfMemoryError thrown while trying to throw OutOfMemoryError; no stack trace available

▼魔方 西西 提交于 2019-12-31 03:05:03
问题 I am trying to compare values of lat long provided by user with values of lat long from database. If they are in 15 km radius of each other textview should be changed. But i am facing following error, My database contains value source lat = 19.218418 source long = 73.08661 Des lat = 18.9766017 des long = 72.8326658. and values provided by user are soure lat = 19.2213935 source long= 73.081532 des lat = 18.9632933 des long = 72.8324848. E/AndroidRuntime: FATAL EXCEPTION: main Process: com

What causes Winforms to silently discard unhandled exceptions (with no try/Catches)?

本秂侑毒 提交于 2019-12-30 23:05:56
问题 I'm in the middle of adding new functionality to my winforms controls, and part of that requires that a variable that was once always used to now be optional (if it's null, get the data from a second source). I made some changes and ran my form, only to find out nothing was happening, even functionality that previously worked. Confused I stepped through the code and found out that my Winforms user control was throwing a NullReferenceException when it encountered my variable, but in the UI no

Can I not catch a specific or custom exception?

穿精又带淫゛_ 提交于 2019-12-30 18:32:31
问题 I dont want to catch some exception. Can I do it somehow? Can I say something like this: catch (Exception e BUT not CustomExceptionA) { } ? 回答1: try { } catch (Exception ex) { if (ex is CustomExceptionA) { throw; } else { // handle } } 回答2: try { // Explosive code } catch (CustomExceptionA){ throw; } catch (Exception ex) { //classic error handling } 回答3: Starting with C# 6, you can use an exception filter: try { // Do work } catch (Exception e) when (!(e is CustomExceptionA)) { // Catch

TRY/CATCH_ALL vs try/catch

安稳与你 提交于 2019-12-30 18:24:10
问题 I've been using c++ for a while, and I'm familiar with normal try/catch. However, I now find myself on Windows, coding in VisualStudio for COM development. Several parts of the code use things like: TRY { ... do stuff } CATCH_ALL(e) { ... issue a warning } END_CATCH_ALL; What's the point of these macros? What benefit do they offer over the built-in try/catch? I've tried googling this, but "try vs TRY" is hard to search for. 回答1: It's an MFC macro: http://msdn.microsoft.com/en-us/library

No exception of type DataAccessException can be thrown; an exception type must be a subclass of Throwable

人盡茶涼 提交于 2019-12-30 17:21:32
问题 My source code like below. It has a error, "No exception of type DataAccessException can be thrown; an exception type must be a subclass of Throwable". I can't understand why the error ocurrs. let me know. thx. package com.sds.afi.cosmos.cmm.db.impl; import java.sql.SQLException; import java.util.HashMap; import java.util.List; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.dao.DataAccessException; import org.springframework.orm.ibatis