program-flow

Current possibilities for tracing program flow in C#?

孤人 提交于 2020-01-26 17:20:18
问题 I have used Postsharp a few years ago to trace program flow during execution without needing to manually add trace statements to the methods. Is there any other new ways to trace execution to to debug output in a similar way? (Preferably a way that doesn't need to instrument the built assemblies. Maybe not possible?) 回答1: If you only want this ability at debug time, there's Microsoft IntelliTrace that's a part of Visual Studio 2010 Ultimate, and there's Sergey Vlasov's RunTime Flow. The

Accessing the containing class of an inner class in Java

旧城冷巷雨未停 提交于 2019-12-30 16:24:26
问题 This is what I'm doing now. Is there a better way to access the super class? public class SearchWidget { private void addWishlistButton() { final SearchWidget thisWidget = this; button.addClickHandler(new ClickHandler() { public void onClick(ClickEvent event) { // A better way to access the super class? // something like "this.super" ...? workWithWidget(thisWidget); } } } } I'm programming with Google Web Toolkit, but I think this is really a generic Java question. 回答1: You can use what is

Java language convention; getters/setters

夙愿已清 提交于 2019-12-24 00:56:04
问题 Public class Example { private int number; public Example(int number){ this.number = number; } public int getNumber(){ return number; } public void setNumber(int number){ this.number = number; } public static void main(String[] args){ Example e = new Example(5); What is preffered when accessing a variable within its own class; "e.number" or "e.getNumber()" ? Edit : I think the most important question is: does the compiler know the method you call is a getter or setter. So, will e.setNumber(5)

Do we need to create a error handler for each subroutine?

 ̄綄美尐妖づ 提交于 2019-12-22 07:16:22
问题 I copy a piece of code from SO as an example. The subroutine contains an error handler. Should one make an error handler for all Subs? Public Sub SubA() On Error Goto ProcError Connection.Open Open File for Writing SomePreciousResource.GrabIt ProcExit: Connection.Close Connection = Nothing Close File SomePreciousResource.Release Exit Sub ProcError: MsgBox Err.Description Resume ProcExit End Sub And by the way, how does the flow of the control inside a subroutine when the code executor

How to find out who is the caller of a method or function? [duplicate]

左心房为你撑大大i 提交于 2019-12-21 06:16:14
问题 This question already has answers here : How to find out who called a method? (9 answers) Closed 5 years ago . I want to write a debug function or method that will help print useful information. When it is called, I need: the memory address of the calling object (if called by an object) the method signature of the caller (or the name of the method), or the name of the function the class name that owns that method or function Is it possible to get this information without passing a whole bunch

Java: why is this code not working? Infinite loop?

让人想犯罪 __ 提交于 2019-12-20 02:53:01
问题 So as you may be able to tell from my attempt, I'm trying to figure out how I'd make a program which gives the user 5 seconds to enter some lines of text, then the Scanner will count how many lines were entered. I've just started learning Java as my 2nd language, so please try to explain everything as simply as possible :) I've got two theories as to why it's not working. The first is that nextLine() will return the whole line, regardless of whether it's empty or not meaning rather than NL

Proper disposal of filestreams and binary streams and disposing of filestreams

时光总嘲笑我的痴心妄想 提交于 2019-12-12 13:26:51
问题 As it is, I tried error-proofing my code and ended up making it look quite messy. I have a function set up to read a certain type of file. I want the function to return false if there was a problem, or true if everything worked. I'm having trouble figuring out how to structure everything. I have an initial try-catch block that tries to open a file stream. After that though, I have certain other checks I make during the reading process such as file size and values at certain offsets. The way I

try-catch-finally block in java

巧了我就是萌 提交于 2019-12-10 19:22:29
问题 As per my understanding, I want to follow the best practice for releasing the resources at the end to prevent any connection leaks. Here is my code in HelperClass. public static DynamoDB getDynamoDBConnection() { try { dynamoDB = new DynamoDB(new AmazonDynamoDBClient(new ProfileCredentialsProvider())); } catch(AmazonServiceException ase) { //ase.printStackTrace(); slf4jLogger.error(ase.getMessage()); slf4jLogger.error(ase.getStackTrace()); slf4jLogger.error(ase); } catch (Exception e) {

How do i make the mutex not be recusive?

一世执手 提交于 2019-12-08 11:06:30
问题 I ran the code below expecting flow to be locked on the 2nd time i lock a mutex. After running it twice i realize it can lock many times (assuming in the same thread) without stopping. How do i change this behavior? using System; using System.Collections.Generic; using System.Text; using System.Threading; namespace Test { class Program { static volatile Mutex mut1 = new Mutex(); static volatile Mutex mut2 = new Mutex(); static void Main(string[] args) { mut1.WaitOne(); Console.WriteLine("1W")

Returning/Stopping the execution of a function on a keypress in Java

淺唱寂寞╮ 提交于 2019-12-08 07:50:47
问题 I have a certain function in my program that I want to stop on the press of a key. I have a native keyboard hook set up for that purpose. Right now, I call System.exit(0) when that key is detected. However, I don't want to exit the program, just stop that operation and return to where it was called. An example is given below. public class Main { public static void main(String[] args) { System.out.println("Calling function that can be stopped with CTRL+C"); foo(); // Should return when CTRL+C