exception-handling

Ideal error page for Java EE App

徘徊边缘 提交于 2019-12-22 13:59:42
问题 I'm having a tough time consolidating errors in my application. Currently, my error.jsp looks like following (part of it): <%@ page isErrorPage="true" %> <%@page contentType="text/html"%> <%@page import="java.util.*"%> <%@page import="javax.servlet.*"%> <%@page import="javax.servlet.http.*"%> <%@page import="java.util.Calendar"%> <%@page import="java.text.SimpleDateFormat"%> <html> <% String code = null, message = null, type = null, uri = null, time = null; Object codeObj=null, messageObj

Java sockets: best way to retry upon Connection Refused exception?

≯℡__Kan透↙ 提交于 2019-12-22 12:29:27
问题 Right now I'm doing this: while (true) { try { SocketAddress sockaddr = new InetSocketAddress(ivDestIP, ivDestPort); downloadSock = new Socket(); downloadSock.connect(sockaddr); this.oos = new ObjectOutputStream(downloadSock.getOutputStream()); this.ois = new ObjectInputStream(downloadSock.getInputStream()); break; } catch (Exception e) {} } downloadSock.connect(sockaddr) will generate a ConnectionRefused exception if the remote host is not listening on the socket. I'm running my code in a

yii2: Proper way to throw new exception

萝らか妹 提交于 2019-12-22 12:23:45
问题 Just for testing I have added this code in my model while setting the debug = true and false. if($packagedays < 1) { throw new \yii\base\Exception( "package days cannot be less than 1" ); } Now when Yii debug is true: I am getting Exception – yii\base\Exception package days cannot be less than 1 But when I am setting the debug to false I am getting Exception An internal server error occurred. The above error occurred while the Web server was processing your request. What I want is to replace

How to check ErrorCode for REGDB_E_CLASSNOTREG?

那年仲夏 提交于 2019-12-22 11:37:17
问题 try { // call to Com Method } catch (COMException e) { if (e.ErrorCode == 0x80040154) // REGDB_E_CLASSNOTREG. { // handle this error. } } I would like to check if com exception is thrown due to REGDB_E_CLASSNOTREG then handle it. I tried with the code above but it gives warning: Comparison to integral constant is useless; the constant is outside the range of type 'int' I believe this error is due to 0x80040154 is not in Int32 range. Can you suggest any possible solution? or Is there any other

Getting Cross-thread operation not valid in MDIParent [duplicate]

房东的猫 提交于 2019-12-22 11:28:52
问题 This question already has answers here : Closed 7 years ago . Possible Duplicate: Cross-thread operation not valid I am trying to close the base of a form from another thread. I am getting the following error. System.InvalidOperationException: Cross-thread operation not valid: Control 'MDIParent' accessed from a thread other than the thread it was created on. for the below line: MDIParent.MDIParentRef.BaseClose(); 回答1: You need to perform the operation on the UI Thread: if (InvokeRequired)

How to include task parameter In array of tasks exception handling

淺唱寂寞╮ 提交于 2019-12-22 10:49:24
问题 The thread Nesting await in Parallel.ForEach has an answer suggested to use Task.WhenAll to run multiple (MaxDegreeOfParallelism) asynchronous tasks in parallel, not waiting until previous task is completed. public static Task ForEachAsync<T>( this IEnumerable<T> source, int dop, Func<T, Task> body) { return Task.WhenAll( from partition in Partitioner.Create(source).GetPartitions(dop) select Task.Run(async delegate { using (partition) while (partition.MoveNext()) await body(partition.Current)

Can someone explain exactly what happens if an exception is thrown during the process of allocating an array of objects on the heap?

Deadly 提交于 2019-12-22 10:18:42
问题 I defined a class foo as follows: class foo { private: static int objcnt; public: foo() { if(objcnt==8) throw outOfMemory("No more space!"); else objcnt++; } class outOfMemory { public: outOfMemory(char* msg) { cout << msg << endl;} }; ~foo() { cout << "Deleting foo." << endl; objcnt--;} }; int foo::objcnt = 0; And here's the main function: int main() { try { foo* p = new foo[3]; cout << "p in try " << p << endl; foo* q = new foo[7]; }catch(foo::outOfMemory& o) { cout << "Out-of-memory

Where to catch exception in PHP MVC application?

大城市里の小女人 提交于 2019-12-22 08:47:13
问题 I have small/mid sized PHP application built for practicing OOP and MVC skills. I have init/bootstrap file which calls Router who calls Controller -> Service Layer -> Repository (Database) and then sends back variables to View Layer (all dependencies handled with DiC/IOC). I created abstract class BaseException that extends Core Exception class. Then I have different Exception classes - DatabaseException, FileException etc. Example triggering Exception: In Database Layer I try to fetch data

WCF Test Client : Failed to add a service. Service metadata may not be accessible. Make sure your service is running and exposing metadata

妖精的绣舞 提交于 2019-12-22 08:39:46
问题 I am currently trying to get the sync framework sample working: sample The solution compiles with out any error or warning. But when I hit F5 the WCF Test Client launches and throws the following error. Local\Temp\Test Client Projects\10.0\5b6aab8a-6629-4a12-87c2-e9e75ba9c1e4\Client.cs(379,13) : error CS0246: The type or namespace name 'schema' could not be found (are you missing a using directive or an assembly reference?) Below is the code from Client.cs that the above error is referencing

Contains Query on multiple columns

时光总嘲笑我的痴心妄想 提交于 2019-12-22 08:37:07
问题 How do I search multiple columns using LINQ to SQL when any one of the column could be null? IEnumerable<User> users = from user in databaseUsers where user.ScreenName.Contains(search) || user.FirstName.Contains(search) || user.LastName.Contains(search) select user; I keep getting this exception: Object reference not set to an instance of an object. Description: An unhandled exception occurred during the execution of the current web request. Please review the stack trace for more information