try-catch

Why isn't SymGetSymFromAddr64 working? It returns error code 126

一世执手 提交于 2019-12-19 10:09:06
问题 I am trying to capture a stack trace on exceptions using the following code: #include "stdafx.h" #include <process.h> #include <iostream> #include <Windows.h> #include "dbghelp.h" using namespace std; #define TRACE_MAX_FUNCTION_NAME_LENGTH 1024 void function2() { int a = 0; int b = 0; throw new exception; } void function1() { int a = 0; function2(); } void function0() { function1(); } LONG WINAPI FatalExceptionFilter(EXCEPTION_POINTERS* exception, DWORD exceptionCode) { CONTEXT *context =

how to catch a “Maximum call stack size exceeded” error?

被刻印的时光 ゝ 提交于 2019-12-19 09:49:57
问题 try { requestAnimationFrame(function re(){ re(); })} catch (e){ console.log(e); } I tried above code in console, it doesn't work as expected. It seems to me that although requestAnimationFrame(function re(){ re(); })} will eventually trigger an error, what throws to the try is insteadly the animation's id. How do I catch such a "Maximum call stack size exceeded" error? 回答1: the thing about catching a maximum stack size exceeded error is I'm not sure how it would work. The only thing that the

PHP: Dynamic or Programmatic Catch Blocks

拟墨画扇 提交于 2019-12-19 06:57:31
问题 I have a situation where it would be nice to be able to have a catch block where the type of the Exception is determined at run time. It would work something like this: $someClassName = determineExceptionClass(); try { $attempt->something(); } catch ($someClassName $e) { echo 'Dynamic Exception'; } catch (Exception $e) { echo 'Default Exception'; } Is this at all possible? 回答1: That doesn't work as far as I'm aware. You could mimic that functionality with a control statement like this:

Java return value (in try/catch clause)

陌路散爱 提交于 2019-12-19 06:45:14
问题 everyone. I have a rookie question about the returning value in java. Here's my code. @Override public long addDrugTreatment(long id, String diagnosis, String drug, float dosage) throws PatientNotFoundExn { try { Patient patient = patientDAO.getPatientByDbId(id); long tid = patient.addDrugTreatment(diagnosis, drug, dosage); Connection treatmentConn = treatmentConnFactory.createConnection(); Session session = treatmentConn.createSession(true, Session.AUTO_ACKNOWLEDGE); MessageProducer producer

Thorough use of 'if' statements or 'try/catch' blocks?

本小妞迷上赌 提交于 2019-12-19 05:46:27
问题 Give me some of your thoughts on which is a better coding practice/makes more efficient code/looks prettier/whatever: Increasing and improving your ability to use if statements to anticipate and catch potential problems? Or simply making good use of try/catch in general? Let's say this is for Java (if it matters). Edit: I'm presently transitioning myself away from some admittedly out-dated and constrained current coding practices, but I'm a little torn on the necessity of doing so on a few

Exception on BitmapFrame.Create (bug in WPF framework?)

China☆狼群 提交于 2019-12-19 05:33:04
问题 I implemented a C# application that recevies frame RGB at framerate of 30fps. The event of frame arrive is managed with this code: void client_ColorFrameReady(object sender, ColorFrameReadyEventArgs e) { mycounter++; Console.WriteLine("new frame received: " + mycounter); if (writer != null) { count++; if (count % 2== 0) { using (var frame = BitmapImage2Bitmap(e.ColorFrame.BitmapImage)) using (var thumb = ResizeBitmap(frame, 320, 240)) { writer.WriteVideoFrame(thumb); } } } else { writer.Close

Unreported exception java.lang.exception

心不动则不痛 提交于 2019-12-19 05:09:32
问题 Unreported exception java.lang.exception : Must be caught or declared to be throw. Why this problem will occur? Is it some simple method that can help to solve this problems? I apply this code in my java.. public byte[] encrypt(String message) throws Exception { MessageDigest md = MessageDigest.getInstance("md5"); byte[] digestOfPassword = md.digest("ABCDEABCDE" .getBytes("utf-8")); byte[] keyBytes = Arrays.copyOf(digestOfPassword, 24); for (int j = 0, k = 16; j < 8;) { keyBytes[k++] =

Java Remove repeated try, catch, finally boilerplate from DAO

ぃ、小莉子 提交于 2019-12-19 03:54:26
问题 I have a DAO class with many methods that have a lot of repeated code along the lines of: - public void method1(...) { Connection conn = null; try { //custom code here } catch (SQLException e) { LOG.error("Error accessing the database.", e); throw new DatabaseException(); } catch (QueryNotFoundException e) { LOG.error("Error accessing the database.", e); throw new DatabaseException(); } finally { if (conn != null) connectionPool.returnConnection(conn); } public void method2(...) { Connection

Try/Catch inside or outside functions

扶醉桌前 提交于 2019-12-19 02:39:07
问题 I have a very basic question about best practice of using try / catch . I have a simple function (DAO) like this public void addVehicle(Vehicle vehicle) { em.getTransaction().begin(); em.persist(vehicle); em.getTransaction().commit(); } and using DAO function inside web service: @WebMethod(operationName = "addVehicle") public void addVehicle(Vehicle vehicle) { try { vehicleDAO.addVehicle(vehicle); System.out.print("Vehicle added"); } catch (Exception e) { e.printStackTrace(); } } OR is better

R avoiding “restarting interrupted promise evaluation” warning

若如初见. 提交于 2019-12-18 18:49:39
问题 Problem It seems that within a function, when you evaluate an expression that yields an error more than once, you get the warning restarting interrupted promise evaluation . For instance: foo <- function() stop("Foo error") bar <- function(x) { try(x) x } bar(foo()) yields Error in foo() : Foo error Error in foo() : Foo error In addition: Warning message: In bar(foo()) : restarting interrupted promise evaluation How to avoid this warning and deal with it properly? Background Especially with