visual studio 2015 not stopping on exception line of code - exception

I just installed visual studio on my desktop and was creating a test solution to learn my way around. I created a solution with 2 projects, one of an IDataReader implementation of a CSV reader and another windows form app to display the reader in a datagridview.
The Reader generates an exception as expected, but it does not stop on the line of code which threw the exception. The reader gets instantiated correctly. But when I go to load it into a datatable it throws an exception on Table.Load(Reader)
The exception is occurring somewhere inside the reader but it is not stopping where the exception is actually occurring.
My dataReader looks like this:
public class DelimitedReader : IDataReader{....lots of code here...}
My form accesses the Delimitedreader like this:
private void openFileDialog1_FileOk(object sender, CancelEventArgs e)
{
try
{
DelimitedReader Reader = new DelimitedReader(openFileDialog1.FileName);
DataTable Table = new DataTable("Data");
Table.Load(Reader);<<<<<<<<Exception stops on this line of code
Grid.DataSource = Table;
}
catch(Exception ex)
{
MessageBox.Show(ex.Message);
}
}
I have:
turned on the CLR exceptions in the "Exception Settings Window"
made sure "Debug Info" was set to Full on both projects
Turned on XML documentation for both, which I think is unnecessary
What am I missing?

My guess is that your reader does a throw new Exception. This causes VS to stop at a higher level exception handler.

Related

Actual exception is not getting logged in MVC when host in IIS

I am running one MVC application where i found one exception in specific method. I will provide here complete details about it.
I am loading some third party grid control from view. to load it i used below code:
#{Html.RenderAction("MasterGridAction", "MyController");}
Now when i access this report from development then this view load and it hits this action method where i used some piece of code there it is throwing error, To catch the error i used try catch block in the method where in catch section i used below code to throw the actual exception like below:
catch (Exception ex)
{
System.Runtime.ExceptionServices.ExceptionDispatchInfo.Capture(ex).Throw(); throw;
}
When exception get catched it sends this to the Application_Error method in global.asax page where i used below code to find out the actual exception like below:
void Application_Error(object sender, EventArgs e)
{
HttpServerUtility server = HttpContext.Current.Server;
if (server.GetLastError() != null)
{
Exception exception = server.GetLastError();
if (exception.GetBaseException() != null)
{
exception = exception.GetBaseException();
ExceptionType(server, exception);
}
else
{
ExceptionType(server, exception);
}
}
}
In this ExceptionType method i get the exception stack and log to the file using "Log4Net". After logging to the file i could see the exception in notepad like below:
Object reference not set to an instance of an object.
Source File: /MyController/MasterGridAction
Stack Trace:
at 3D.Controllers.MyController.MasterGridAction() in D:\MyUser\3D_MVC\Application\3D_OnlyRelease\3D\Controllers\MyController.cs:line 405
--- End of stack trace from previous location where exception was thrown ---
As we can see in above exception it is clearly shown the line number also where this exception get caught.
But once i host this application in IIS server and access the same page then i could see the logged file
There it shows exception like below:
Exception Message: Object reference not set to an instance of an object.
Stack Trace: at 3D.Controllers.MyController.MasterGridAction()
--- End of stack trace from previous location where exception was thrown ---
As you can see the logged exception of IIS server is not having much information when compare to other exception details.
Am i missing anything there to get the complete exception when host in IIS?
Please suggest.
As you can see the logged exception of IIS server is not having much information when compare to other exception details.
This could be because you don't include the PDB files in production.
It might not be a great idea to include them, since that way one can reverse engineer you app with more precision if they hack your server, but it is up to you to decide. I have seen organizations that include them in their production environments.
Try publishing and deploying on a test environment with and without the PDB files to verify this.

Create an exception message in a new window on Java, not on the console

I know how to create an exception that appears in the console, but I want to create a new window that throws an exception so it will be visible to the user.
Any suggestions?
Never mind I handled it.
Just use this code:
JOptionPane.showMessageDialog(null, String message);

Monotouch crashes with no exceptions

I built a monotouch app it randomly crashes after user fnishes signup the problem is that no exception is being thrown, I tried to catch that with the debugger while testing it on a device (of course I set it up to catch all exceptions) I even tried to set up crash tool such as HockeyApp but those crashes don't appear any where.
How can I solve this? help please!
You should check out Raygun.io. It will log any unhandled exceptions to the dashboard. Add it via a nuget package and then you can set it up with one line in your Main.cs:
namespace Myapp.iOS
{
public class Application
{
// This is the main entry point of the application.
static void Main(string[] args)
{
Mindscape.Raygun4Net.RaygunClient.Attach("enter your api key here");
UIApplication.Main(args, null, "AppDelegate");
}
}
}

ejb-3.0 customized exception

My ejb3 application running on JBOSS6 already has a customized Exception handler "Ejbexception.java" which extends Exception class
I want to use the same to trap Exceptions with some number and send back the same to the Client Code for handling gentel message .
ex:
try{
.....
}catch(SQLException ex){
throw new EjbException("1001");
}
Now HOWto get the "1001" on the Client Code ?????
thx in advance
karthik
Did you write this Ejbexception class yourself? If so, that's a poor choice of name, because there's already a javax.ejb.EJBException in the library. However, it will work: when you throw it, the container will transport it to the client, who can then catch it. The string you inserted will be available from the exception's getMessage() method, just like normal.
If you're actually throwing a javax.ejb.EJBException here, then things are slightly different. That exception is aimed at the container, not the client. I actually don't know how it's made visible to the client. My suggestion would be to switch to using a custom exception, which the container will then pass to the client.

Final managed exception handler in a mixed native/managed executable?

I have an MFC application compiled with /clr and I'm trying to implement a final handler for otherwise un-caught managed exceptions. For native exceptions, overriding CWinApp::ProcessWndProcException works.
The two events suggested in Jeff's CodeProject article,Application.ThreadException and AppDomain.CurrentDomain.UnhandledException, are not raised.
Can anyone suggest a way to provide a final managed exception handler for a mixed executable?
Update:
It appears that these exception handlers are only triggered downstream of Application.Run or similar (there's a worker thread flavor, can't remember the name.) If you want to truly globally catch a managed exception you do need to install an SEH filter. You're not going to get a System.Exception and if you want a callstack you're going to have to roll your own walker.
In an MSDN forum question on this topic it was suggested to override a sufficiently low-level point of the main MFC thread in a try ... catch (Exception^). For instance, CWinApp::Run. This may be a good solution but I haven't looked at any perf or stability implications. You'll get a chance to log with a call stack before you bail and you can avoid the default windows unahndled exception behavior.
Taking a look around the internets, you'll find that you need to install a filter to get the unmanaged exceptions passing the filters on their way to your AppDomain. From CLR and Unhandled Exception Filters:
The CLR relies on the SEH unhandled exception filter mechanism to catch unhandled exceptions.
Using those two exception handlers should work.
Why "should?"
The events are not raised using the below:
extern "C" void wWinMainCRTStartup();
// managed entry point
[System::STAThread]
int managedEntry( void )
{
FinalExceptionHandler^ handler = gcnew FinalExceptionHandler();
Application::ThreadException += gcnew System::Threading::ThreadExceptionEventHandler(
handler,
&FinalExceptionHandler::OnThreadException);
AppDomain::CurrentDomain->UnhandledException += gcnew UnhandledExceptionEventHandler(
handler,
&FinalExceptionHandler::OnAppDomainException);
wWinMainCRTStartup();
return 0;
}
// final thread exception handler implementation
void FinalExceptionHandler::OnThreadException( Object^ /* sender */, System::Threading::ThreadExceptionEventArgs^ t )
{
LogWrapper::log->Error( "Unhandled managed thread exception.", t->Exception );
}
// final appdomain exception handler implementation
void FinalExceptionHandler::OnAppDomainException(System::Object ^, UnhandledExceptionEventArgs ^args)
{
LogWrapper::log->Error( "Unhandled managed appdomain exception.", (Exception^)(args->ExceptionObject) );
}
BOOL CMyApp::InitInstance()
{
throw gcnew Exception("test unhandled");
return TRUE;
}
Using those two exception handlers should work. Are you sure you've added them in a place where they're going to be called and properly set (ie, in your application's managed entry point -- you did put one in, right?)