exception-handling

Why Application.OnException never runs?

前提是你 提交于 2020-01-17 17:15:03
问题 Problem summary: The method assigned to Application.OnException never runs when an unhandled exception occurs. I create a blank project with only this unit and place a single button on Unit.dfm (this is based on an official example) : // Unit1.pas // ********* type TForm1 = class(TForm) Button1: TButton; procedure FormCreate(Sender: TObject); procedure AppException(Sender: TObject; E: Exception); procedure Button1Click(Sender: TObject); end; var Form1: TForm1; implementation {$R *.dfm}

Why Application.OnException never runs?

萝らか妹 提交于 2020-01-17 17:14:28
问题 Problem summary: The method assigned to Application.OnException never runs when an unhandled exception occurs. I create a blank project with only this unit and place a single button on Unit.dfm (this is based on an official example) : // Unit1.pas // ********* type TForm1 = class(TForm) Button1: TButton; procedure FormCreate(Sender: TObject); procedure AppException(Sender: TObject; E: Exception); procedure Button1Click(Sender: TObject); end; var Form1: TForm1; implementation {$R *.dfm}

Handling XmlDataSource when remote XML source not available

陌路散爱 提交于 2020-01-17 07:02:26
问题 When using an XmlDataSource is there good way to handle exceptions that are caused when the remote XML file is unavailable? I'm somewhat new to .NET and using C#. 回答1: It's really up to you to determine what is suitable for your application when an exception like this is raised. The only thing you shouldn't do is ignore it. Options you have include: Automatically retry a number of times, in case the connection problem is transitory Return an appropriate error message to the user and perhaps

EntitySqlException on select with code first dbcontext in Entity Framework

天涯浪子 提交于 2020-01-17 05:34:20
问题 When var codeFirstRepositor = new Donors(); var list = codeFirstRepositor.CampaignReps.Select(c => c).ToList(); When I put a breakpoint inside the CampaignRep class constructor it is not called at all - the exception seems to occur before object instantiation Context public class Donors : DbContext { public Donors() { // Needed for WCF serialization to work Configuration.ProxyCreationEnabled = false; } public DbSet<CampaignRep> CampaignReps { get; set; } } EntitySqlException 'CampaignsReps'

Python3 Catch errors when from self.connect(('badhost',6667))

主宰稳场 提交于 2020-01-16 18:35:30
问题 Looks like asyncio is the module to use. I'll leave this question up anyway, because it doesn't look like there is a way to catch specific errors with asynchat. class mysocket(asynchat.async_chat): terminator = b'\n' def __init__(self,sock=None): asynchat.async_chat.__init__(self,sock) self.create_socket() # Try always succeeds with self.connect try: self.connect(('badhost',6667)) print('command always successful') except: print('This never gets printed') How do I catch errors from the self

How does one correctly create and access a KeyStore in java to store an encryption key?

丶灬走出姿态 提交于 2020-01-16 14:32:10
问题 I've been mixing and matching code, trying to learn by example for using KeyStores. I have this createKeyStore method: private static KeyStore createKeyStore(String fileName, String pw) throws Exception { File file = new File(fileName); final KeyStore keyStore = KeyStore.getInstance("JCEKS"); if (file.exists()) { // .keystore file already exists => load it keyStore.load(new FileInputStream(file), pw.toCharArray()); } else { // .keystore file not created yet => create it keyStore.load(null,

Exception not caught after signal

痴心易碎 提交于 2020-01-16 08:20:30
问题 I try to catch a termination signal to my code to write a restart file before exiting. My solution is based on this answer. #include <exception> #include <csignal> #include <iostream> class InterruptException : public std::exception { public: InterruptException(int _s) : signal_(_s) { } int signal() const noexcept { return this->signal_; } private: int signal_; }; /// method to throw exception at signal interrupt void sig_to_exception(int s) { throw InterruptException(s); } int main() { //

how to circumvent Kotlin's restriction “Type parameter is forbidden for catch parameter”

≯℡__Kan透↙ 提交于 2020-01-16 05:04:46
问题 I have defined the following function: inline fun <T> T.tryTo(block: T.() -> Unit): T? { try { block() } catch (ex: IllegalArgumentException) { return this } return null } The purpose is to build a chain of try-actions on an object, e.g.: val input: String = getInput(); input.tryTo /* treat as a file name and open the file */ { Desktop.getDesktop().open(File(this)) }?.tryTo /* treat as a number */ { try { doSomethingWithTheNumber(parseInt(this)) } catch (ex: NumberFormatException) { throw

C# detect offline mode (SQL Server connection)

人走茶凉 提交于 2020-01-15 12:05:13
问题 I am developing a C# application which connects to SQL Server. If the network connection breaks, the application should be able to go into a "read-only mode" (offline mode) and only read data from a local database. Right now, I am trying to figure out how to detect the disconnect: public int executeNonQuery(string query, List<SqlParameter> parameters) { int result; using (SqlConnection sqlConnection = new SqlConnection(ConnectionString)) { tryOpenSqlConnection(sqlConnection); using

C# detect offline mode (SQL Server connection)

白昼怎懂夜的黑 提交于 2020-01-15 12:04:26
问题 I am developing a C# application which connects to SQL Server. If the network connection breaks, the application should be able to go into a "read-only mode" (offline mode) and only read data from a local database. Right now, I am trying to figure out how to detect the disconnect: public int executeNonQuery(string query, List<SqlParameter> parameters) { int result; using (SqlConnection sqlConnection = new SqlConnection(ConnectionString)) { tryOpenSqlConnection(sqlConnection); using