A generic internal error page should be shown when an unexpected exception is thrown in wicket6.x or wicket7.7? - wicket-1.5

protected void init() {
getApplicationSettings().setInternalErrorPage(BnafInternalErrorPage.class);
getApplicationSettings().setPageExpiredErrorPage(BnafAccessDeniedErrorPage.class);
getApplicationSettings().setAccessDeniedPage(BnafAccessDeniedErrorPage.class);
getExceptionSettings().setInternalErrorPage(IExceptionSettings.SHOW_INTERNAL_ERROR_PAGE);
In above code i got error at IExceptionSettings.

IExceptionSettings removed in wicket 7
So you can replace this below line.
getExceptionSettings().setInternalErrorPage(IExceptionSettings.SHOW_INTERNAL_ERROR_PAGE);
to
getExceptionSettings().setUnexpectedExceptionDisplay(ExceptionSettings.SHOW_INTERNAL_ERROR_PAGE);
To know more details check here
https://cwiki.apache.org/confluence/display/WICKET/Migration+to+Wicket+7.0#MigrationtoWicket7.0-AllIXyzSettingsareremovedWICKET-5410

Related

Guidewire Exception handling in UI

when internal Guidewire code throws an exception you get a nicely formatted error message box. However, when custom code throws an exception you are directed to the error page (with the red stack trace text & back to application button). Is there anything in the Guidewire framework to make proper UI handling of errors nicer?
such as: < TextBox value="user.someMethod()"/>
//someMethod code...
try{
return user.someOtherCode()
}catch(e : Exception){
//TODO: gracefully display erorr mesage on page
//e.g. showErrorMessage()
return null
}
You have a simpler way to do this,
The below piece of code can be written in helper class or any Enhancement or even in PCF code tab, this will return a nice formatted error message.
gw.api.util.LocationUtil.addRequestScopedErrorMessage("Your error message")
After some searching through Guidewire OOTB code UserDisplayableExceptions are what you need - answering myself in case someone else has this thought.
function goToPolicy(bulkDocumentDownload : BulkDocDownload_Avi) {
try {
throw new IndexOutOfBoundsException("Ops! some index out of bounds exception was thrown")
} catch (e : Exception) {
throw new com.guidewire.pl.web.controller.UserDisplayableException(e.Message)
}
}

Error executing code object not initialized in AX 2009

I am receiving a message in my custom project within AX 2009 when calling a method from a referenced dll I created. The message is Error executing code object not initialized. I have my project compiled successfully and the dll is referenced in the AOT.
The error occurs in MyClassExecuteCopy.copy() when trying to perform hostServices.Copy()
Can anyone see any issues as to why I would be receiving this message?
I shortened the code for this example as follows:
//classDeclaration
class MyClassExecute extends RunbaseBatch
{
MyDll.Win.HostServices hostServices;
MyDll.Data.InputParameters inputParams;
MyDll.Test.Data.ResultSummary resultSummary;
}
//MyClassExecute.initLiabraries
public void initLiabraries()
{
;
new InteropPermission(InteropKind::ClrInterop).assert();
hostServices = new MyDll.Win.HostServices();
inputParams = new MyDll.Data.InputParameters();
CodeAccessPermission::revertAssert();
}
////////////////////////////////////////////
class MyClassExecuteCopy extends MyClassExecute
{
}
//MyClassExecuteCopy.copy - Exception occurs on resultSummary line with "Error executing code: copySomething object not initialized"
void copy()
{
new InteropPermission(InteropKind::ClrInterop).assert();
//Exception occurs when executing line below with "Error executing code: copySomething object not initialized"
resultSummary = hostServices.Copy();
CodeAccessPermission::revertAssert();
}
//////////////////////////////////////////////
class CreateCopy extends Runbase
{
}
//CreateCopy.copySomething
public client server static void copySomething()
{
MyClassExecuteCopy myClassExecuteCopy;
;
new InteropPermission(InteropKind::ClrInterop).assert();
myClassExecuteCopy.initLiabraries();
myClassExecuteCopy.copy();
CodeAccessPermission::revertAssert();
}
Found the issue to be initialized by data.
As a result hostServices.Copy() did not have the correct values and either resulting in an error within the dll or returned nothing either way was the result of the error message i was receiving within AX.
After correcting the data that same call processed as expected.

Inserting or Adding previously removed PivotItem throws invalid argument exception but works, why?

if (!Pivot.Items.Contains(PrevRemovedPivotItem))
{
//Pivot.Items.Insert(1, PrevRemovedPivotItem);
Pivot.Items.Add(PrevRemovedPivotItem);
}
Both the ways throw same exception but at the same time adds the pivotitem.
What's wrong?

How to handle only a specific type of Exception using the HandleError and let the rest of the Exceptions be thrown normally?

I'm working on a team-project and I am in the following situation:
I created my own Exception class, and I want all the thrown exceptions of type myException to be handled and automatically redirected to the Error view where I would nicely display the error, which is ok to do. This is what I added in my Web.config:
<customErrors mode="On" defaultRedirect="Error" />
The issue is I want all the rest of the exceptions to be thrown normally, seeing all the information about it, including the stack trace, the source file and the line error, which would be really good for the team-project.
I've tried the [HandleError(ExceptionType=typeof(myException)], but it is no use.
I also tried to override the OnException function of the controller and if the exception is not myException then i would throw it again, but i still get in the Error view.
protected override void OnException(System.Web.Mvc.ExceptionContext filterContext)
{
if (filterContext.Exception.GetType() != typeof(myException)) {
throw filterContext.Exception;
}
base.OnException(filterContext);
}
Any idea which could work?
Thanks.
You may get the result you want by leaving custom errors Off (so that for all the errors you get the stack trace displayed), and redirecting the exceptions you want to the controller/view you need (so that a friendly-looking page will be displayed).
You could define a base controller for all your controllers, and override its OnException method with something like below:
if (filterContext.Exception.GetType() == typeof(YourCustomException))
{
filterContext.ExceptionHandled = true;
filterContext.Result = RedirectToAction("ActionName", "ControllerName", new { customMessage = "You may want to pass a custom error message, or any other parameters here"});
}
else
{
base.OnException(filterContext);
}

Getting an Unhandled Exception in VS2010 debugger even though the exception IS handled

I have an issue with VS2010 where the debugger stops with an Unhandled Exception. However, the exception is definitely handled. In fact, if I put code in the catch block, I'll hit it when I press F5. In Debug -> Exceptions, I definitely do not have the "Thrown" checkbox checked, so IMO there is absolutely no reason for the unhandled exception dialog to pop up...
I can't post the exact code, but will work on a sample soon. The basic idea behind the offending code section is that I have a thread that talks to hardware, and if I have an error talking to it, then I throw a HardwareException. The thread is launched with BeginInvoke, and the exception is caught in the callback handler when I call EndInvoke.
When the exception is thrown in the debugger, I get a messagebox that says 'HardwareException not handled by user code". But it is!!!
EDIT -- Well, this is driving me crazy. I've got sample code that is representative of the code I have in my application, and it looks like this:
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Runtime.Remoting.Messaging;
using System.Threading;
namespace ConsoleApplication1
{
public class HardwareException : ApplicationException
{
public HardwareException( string message) : base(message) {}
}
class Program
{
delegate void HardwareTestDelegate();
static void Main(string[] args)
{
HardwareTestDelegate d = new HardwareTestDelegate( HardwareTestThread);
d.BeginInvoke( HardwareTestComplete, null);
while( true);
}
static void HardwareTestThread()
{
throw new HardwareException( "this is a test");
}
static void HardwareTestComplete( IAsyncResult iar)
{
try {
AsyncResult ar = (AsyncResult)iar;
HardwareTestDelegate caller = (HardwareTestDelegate)ar.AsyncDelegate;
caller.EndInvoke( iar);
} catch( Exception ex) {
Console.WriteLine( "Should see this line without getting an unhandled exception message in the IDE");
}
}
}
}
I throw my HardwareException from the thread, and then handle the exception when EndInvoke is called. I guess Murphy was right, because when I run this sample code, it does what I expect -- i.e. no unhandled exception error message pops up in the IDE!
Here is the response from Microsoft, case 111053102422121. Allen Weng writes the following:
Analysis:
For your information, CLR will re-throw the exception inside the callback when you call EndInvoke(). Below is a simplified version of EndInvoke():
public object EndInvoke(IAsyncResult asyncResult)
{
using (new MultithreadSafeCallScope())
{
ThreadMethodEntry entry = asyncResult as ThreadMethodEntry;
............
if (entry.exception != null)
{
throw entry.exception;
}
}
}
The exception will be handled in the call back function or in the asynchronous method if an exception handler is provided. This is how it works without a debugger attached.
When you run it in VS.NET, the debugger seems checking only the presence of the exception handler in the asynchronous method. If there is no such handler, the debugger would think the exception is not handled and pop up an error message notifying you of this.
Suggestion:
The application should work as expected when you run it stand alone. If the error message is annoying in debugging for you, you can disable it by unchecking “User unhandled” for “Common Language Runtime Exceptions”in the Exception dialog box (Debug|Exceptions or press CTRL+ATL+E). Or you can add try/catch in the asynchronous method. In the latter case, the exception is set to null and won’t be re-thrown in EndInvoke().
I'm having this same problem, so I'll post this possible workaround for posterity's sake:
In your code that throws an exception into the .NET code (HardwareTestThread() in the example above,) catch the exception that's being thrown and wrap it in some esoteric .NET exception type for which you can disable the "user-unhandled" option in the Debug>Exceptions dialog. For my case, I needed to allow an IOException to propagate through some .NET code back to my code, so I just caught the IOException and wrapped in an AppDomainUnloadedException before letting it propagate through the .NET code back to my catch block. I chose AppDomainUnloadedException because user-unhandled is unchecked for it by default and it's in the System.dll assembly, so it was already being imported in my project, though any exception should work, so long as you disable the "user-unhandled" option for it and you don't care that the debugger won't break on that type of exception in the future.
Here's my code that wraps the IOException I was needing to propagate:
public override int Read(byte[] buffer, int offset, int count)
{
try { return innerStream.Read(buffer, offset, count); }
catch (IOException ex) { throw new AppDomainUnloadedException("Exception from innerStream: " + ex.Message, ex); }
}
And here's my code where I'm catching it on the other side of the .NET code it needed to propagate through:
try { bytesRead = sslStream.Read(buffer, offset, count); }
catch (Exception ex) { /* ex handled here. */ }

Resources